-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LDBR-4.3: ServiceWorker & Offline (#55)
* LDBR-4.3: Внести правки для запуска на localhost * LDBR-4.3: Кэширование в SW * LDBR-4.3: Частично реализовать offline * LDBR-4.3: Исправить проблемы с оффлан работой * LDBR-4.3: Добавить сообщение об оффлайн работе и порезать функционал в офлайне * LDBR-4.3: Исправить замечания линтера * LDBR-4.3: Внести правки в код связанный с SW * LDBR-4.3: Добавить расчет хэша для файла SW * LDBR-4.3: Устранить круговую зависимость SettingStore->Router->NotFoundView->SettingStore * LDBR-4.3: Подключить SettingStore * LDBR-4.3: Изменить replase spate при переходе на /offline
- Loading branch information
Showing
33 changed files
with
2,328 additions
and
211 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict'; | ||
|
||
// Modules | ||
import Dispatcher from '../modules/Dispatcher/Dispatcher.js'; | ||
|
||
/** | ||
* Константа, содержащая в себе типы действий для собыйтий от sw. | ||
*/ | ||
export const ServiceWorkerTypes = { | ||
HALF_OFFLINE: 'half-offline', | ||
FULL_OFFLINE: 'full-offline', | ||
CLOSE_OFFLINE_MSG: 'close-offline', | ||
SHOW_OFFLINE_MSG: 'show-offline', | ||
HIDE_OFFLINE_MSG: 'hide-offline', | ||
}; | ||
|
||
/** | ||
* Класс, содержащий в себе действия для работы с тегами. | ||
*/ | ||
export const serviceWorkerActions = { | ||
|
||
/** | ||
* Отображает предупреждение об offline работе | ||
*/ | ||
responseFromCache() { | ||
Dispatcher.dispatch({ | ||
actionName: ServiceWorkerTypes.HALF_OFFLINE, | ||
}); | ||
}, | ||
|
||
/** | ||
* Отображает offline страницу | ||
*/ | ||
fullOffline() { | ||
Dispatcher.dispatch({ | ||
actionName: ServiceWorkerTypes.FULL_OFFLINE, | ||
}); | ||
}, | ||
|
||
/** | ||
* Сворачивает предупреждение об offline работе | ||
*/ | ||
onCloseOfflineMessage() { | ||
Dispatcher.dispatch({ | ||
actionName: ServiceWorkerTypes.CLOSE_OFFLINE_MSG, | ||
}); | ||
}, | ||
|
||
/** | ||
* Разворачивает offline сообшение | ||
*/ | ||
onOpenOfflineMessage() { | ||
Dispatcher.dispatch({ | ||
actionName: ServiceWorkerTypes.SHOW_OFFLINE_MSG, | ||
}); | ||
}, | ||
|
||
/** | ||
* Скрывает предупреждение об offline работе | ||
*/ | ||
hideOfflineMessage() { | ||
Dispatcher.dispatch({ | ||
actionName: ServiceWorkerTypes.HIDE_OFFLINE_MSG, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{{#with offline}} | ||
{{# if visible }} | ||
<div class="offline__wrapper" | ||
{{# if open }} | ||
class = "offline__wrapper offline__wrapper_non-clickable" | ||
{{ else}} | ||
class = "offline__wrapper offline__wrapper-clickable" | ||
id="offlineMessageShowId" | ||
{{/if}} | ||
> | ||
<div class="material-icon-warning"></div> | ||
{{# if open }} | ||
<div class="offline__message">Похоже у вас отсутствует соединиение с Интернетом<br>Часть функций недоступна.</div> | ||
<div class="close-button" id="offlineMessageCloseId"></div> | ||
{{/if}} | ||
</div> | ||
{{/if}} | ||
{{/with}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Базовый компонент | ||
import BaseComponent from '../BaseComponent.js'; | ||
// Стили | ||
|
||
import './OfflineMessage.scss'; | ||
import UserStore from '../../stores/UserStore/UserStore.js'; | ||
|
||
// Шаблон | ||
import template from './OfflineMessage.hbs'; | ||
|
||
// Action | ||
import {serviceWorkerActions} from '../../actions/serviceworker.js'; | ||
|
||
|
||
/** | ||
* Класс, реализующий компонент OfflineMessage. | ||
*/ | ||
export default class OfflineMessage extends BaseComponent { | ||
/** | ||
* Конструктор, создающий класс компонента OfflineMessage. | ||
* @param {Object} context контекст отрисовки шаблона | ||
*/ | ||
constructor(context) { | ||
super(context, template); | ||
|
||
this._onRefresh = this._onRefresh.bind(this); | ||
UserStore.addListener(this._onRefresh); | ||
|
||
this._elements = {}; | ||
this._bindCallBacks(); | ||
} | ||
|
||
/** | ||
* Метод, вызывающийся по умолчанию при обновлении компонента. | ||
*/ | ||
_onRefresh() { | ||
this.context = UserStore.getContext(); | ||
} | ||
|
||
/** | ||
* Метод биндит callback'и к this | ||
* @private | ||
*/ | ||
_bindCallBacks() { | ||
this._onClose = this._onClose.bind(this); | ||
this._onOpen = this._onOpen.bind(this); | ||
} | ||
|
||
/** | ||
* Метод сохраняет элементы DOM связанные с navbar | ||
* @private | ||
*/ | ||
_registerElements() { | ||
this._elements = { | ||
wrapper: document.getElementById('offlineMessageShowId'), | ||
close: document.getElementById('offlineMessageCloseId'), | ||
}; | ||
} | ||
|
||
/** | ||
* Метод, добавляющий обработчики событий для компонента. | ||
*/ | ||
addEventListeners() { | ||
this._registerElements(); | ||
this._elements.wrapper?.addEventListener('click', this._onOpen); | ||
this._elements.close?.addEventListener('click', this._onClose); | ||
} | ||
|
||
/** | ||
* Метод, удаляющий обработчики событий для компонента. | ||
*/ | ||
removeEventListeners() { | ||
this._elements.wrapper?.removeEventListener('click', this._onOpen); | ||
this._elements.close?.removeEventListener('click', this._onClose); | ||
} | ||
|
||
/** | ||
* CallBack на закрытие сообщения | ||
* @param {Event} event объект события | ||
* @private | ||
*/ | ||
_onClose(event) { | ||
event.preventDefault(); | ||
serviceWorkerActions.onCloseOfflineMessage(); | ||
} | ||
|
||
|
||
/** | ||
* CallBack на открытие сообщения | ||
* @param {Event} event объект события | ||
* @private | ||
*/ | ||
_onOpen(event) { | ||
event.preventDefault(); | ||
serviceWorkerActions.onOpenOfflineMessage(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
@import '../../styles/scss/Constants'; | ||
|
||
.offline { | ||
&__wrapper { | ||
position: fixed; | ||
z-index: 2; | ||
left: 20px; | ||
bottom: 20px; | ||
background-color: $offline-background; | ||
border: 2px solid $offline-border; | ||
border-radius: 20px; | ||
|
||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
align-items: center; | ||
column-gap: 5px; | ||
padding: 5px; | ||
|
||
&_clickable { | ||
cursor: pointer; | ||
} | ||
|
||
&_non-clickable { | ||
cursor: pointer; | ||
} | ||
} | ||
|
||
|
||
&__content { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.