Skip to content

Commit

Permalink
LDBR-4.23: Правки в SW (#56)
Browse files Browse the repository at this point in the history
* LDBR-4.23: Плагин для минимизации JS

* LDBR-4.23: Переключение минимизации JS по флагу

* LDBR-4.23: Исправить ситуация когда приложение не загружало актуальную версию, а использовало кэш

* LDBR-4.23: Добавить функцию для загрузки аттачей в SW

* LDBR-4.23: Исправить 404 при загрузке attachments

* LDBR-4.23: Добавить вывод сообщений о не доступности сети

* LDBR-4.23: Обработка 403 ошибки

* LDBR-4.23: Ипсравить баг

* LDBR-4.23: Исправить баг 2

* LDBR-4.23: Исправить баг 3

* LDBR-4.23: Исправить баг 4

* LDBR-4.23: Исправить баг 5

* LDBR-4.23: Исправить замечание линтера
  • Loading branch information
GeorgiyX authored Dec 24, 2021
1 parent dae404a commit 44c0ab3
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 45 deletions.
29 changes: 15 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"mini-css-extract-plugin": "^2.4.4",
"node-sass": "^6.0.1",
"sass-loader": "^12.3.0",
"terser-webpack-plugin": "^5.3.0",
"webpack": "^5.62.1",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.4.0",
Expand Down
7 changes: 7 additions & 0 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const HttpStatusCodes = {
Unauthorized: 401,
InternalServerError: 500,
Forbidden: 403,
TooLarge: 413,
};

/**
Expand Down Expand Up @@ -104,6 +105,9 @@ export const ConstantMessages = {
CantCopyToClipBoard: 'Не удалось скопировать текст',

WrongTagNameLength: 'Введите имя тега длиной от 1 до 40 символов',

OfflineMessage: 'Операция не удалась - отсутствует соединение с Интернетом',
TooLargeMessage: 'Файл фложения слишком большой',
};

export const BoardStoreConstants = {
Expand All @@ -123,11 +127,14 @@ export const SettingStoreConstants = {
export const ServiceWorker = {
CacheUrls: {
HTML_URL: '/index.html',
OFFLINE_URL: '/offline',
NO_INTERNET_IMG_URL: '/assets/no-internet-icon.webp',
},
API_PREFIX: '/api',
STATIC_CACHE_NAME: `static-cache-${APP_VERSION}`,
API_CACHE_NAME: `api-cache-${APP_VERSION}`,
ATTACHMENT_PREFIX: '/attach',
ATTACH_NAME_PARAM: 'file_name',
SW_HEADER: 'X-Is-From-Service-Worker',
Messages: {
OFFLINE_FROM_CACHE: 'offline-cache', // Приложение работает в offline
Expand Down
68 changes: 48 additions & 20 deletions src/stores/BoardStore/BoardStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
BoardStoreConstants,
CheckLists,
ConstantMessages, HTTP,
HttpStatusCodes,
HttpStatusCodes, ServiceWorker,
Urls,
} from '../../constants/constants.js';

Expand Down Expand Up @@ -599,10 +599,11 @@ class BoardStore extends BaseStore {
* @private
*/
async _updateTitleAndDescription(data) {
this._storage.get('setting-popup').errors = null;
if (SettingsStore.isOffline()) {
this._storage.get('setting-popup').errors = ConstantMessages.OfflineMessage;
return;
}
this._storage.get('setting-popup').errors = null;
const validator = new Validator();

this._storage.get('setting-popup').errors = validator.validateBoardDescription(data.description);
Expand Down Expand Up @@ -708,6 +709,7 @@ class BoardStore extends BaseStore {
*/
async _createCardList(data) {
if (SettingsStore.isOffline()) {
this._storage.get('cardlist-popup').errors = ConstantMessages.OfflineMessage;
return;
}
this._storage.get('cardlist-popup').errors = null;
Expand Down Expand Up @@ -802,6 +804,7 @@ class BoardStore extends BaseStore {
*/
async _updateCardList(data) {
if (SettingsStore.isOffline()) {
this._storage.get('cardlist-popup').errors = ConstantMessages.OfflineMessage;
return;
}
this._storage.get('cardlist-popup').errors = null;
Expand Down Expand Up @@ -956,6 +959,7 @@ class BoardStore extends BaseStore {
*/
async _createCard(data) {
if (SettingsStore.isOffline()) {
this._storage.get('card-popup').errors = ConstantMessages.OfflineMessage;
return;
}
this._storage.get('card-popup').errors = null;
Expand Down Expand Up @@ -1136,6 +1140,7 @@ class BoardStore extends BaseStore {
*/
async _updateCard(data) {
if (SettingsStore.isOffline()) {
this._storage.get('card-popup').errors = ConstantMessages.OfflineMessage;
return;
}
this._storage.get('card-popup').errors = null;
Expand Down Expand Up @@ -1326,10 +1331,11 @@ class BoardStore extends BaseStore {
* @private
*/
async _createCheckList() {
const context = this._storage.get('card-popup');
if (SettingsStore.isOffline()) {
context.errors = ConstantMessages.OfflineMessage;
return;
}
const context = this._storage.get('card-popup');
context.errors = null;

const newCheckList = {
Expand Down Expand Up @@ -1377,10 +1383,11 @@ class BoardStore extends BaseStore {
* @private
*/
async _saveCheckList(data) {
const context = this._storage.get('card-popup');
if (SettingsStore.isOffline()) {
context.errors = ConstantMessages.OfflineMessage;
return;
}
const context = this._storage.get('card-popup');
context.errors = null;
const checkList = this._getCheckListById(data.chlid);

Expand Down Expand Up @@ -1454,10 +1461,11 @@ class BoardStore extends BaseStore {
* @private
*/
async _createCheckListItem(data) {
const context = this._storage.get('card-popup');
if (SettingsStore.isOffline()) {
context.errors = ConstantMessages.OfflineMessage;
return;
}
const context = this._storage.get('card-popup');
context.errors = null;
const checkList = this._getCheckListById(data.chlid);

Expand Down Expand Up @@ -1506,10 +1514,11 @@ class BoardStore extends BaseStore {
* @private
*/
async _saveCheckListItem(data) {
const context = this._storage.get('card-popup');
if (SettingsStore.isOffline()) {
context.errors = ConstantMessages.OfflineMessage;
return;
}
const context = this._storage.get('card-popup');
context.errors = null;
const item = this._getCheckListItemById(data.chlid, data.chliid);

Expand Down Expand Up @@ -1587,10 +1596,11 @@ class BoardStore extends BaseStore {
* @private
*/
async _toggleCheckListItem(data) {
const context = this._storage.get('card-popup');
if (SettingsStore.isOffline()) {
context.errors = ConstantMessages.OfflineMessage;
return;
}
const context = this._storage.get('card-popup');
context.errors = null;
context.selectInvite = false;
let item = this._getCheckListItemById(data.chlid, data.chliid);
Expand Down Expand Up @@ -1707,10 +1717,11 @@ class BoardStore extends BaseStore {
* @private
*/
async _toggleCardAssigneeInSearchList(data) {
const context = this._storage.get('add-card-member-popup');
if (SettingsStore.isOffline()) {
context.errors = ConstantMessages.OfflineMessage;
return;
}
const context = this._storage.get('add-card-member-popup');
context.errors = null;
context.selectInvite = false;

Expand Down Expand Up @@ -1806,10 +1817,11 @@ class BoardStore extends BaseStore {
* @private
*/
async _toggleBoardMemberInSearchList(data) {
const context = this._storage.get('add-board-member-popup');
if (SettingsStore.isOffline()) {
context.errors = ConstantMessages.OfflineMessage;
return;
}
const context = this._storage.get('add-board-member-popup');
context.selectInvite = false;
context.errors = null;

Expand Down Expand Up @@ -1912,10 +1924,11 @@ class BoardStore extends BaseStore {
* @private
*/
async _createCardComment(data) {
const context = this._storage.get('card-popup');
if (SettingsStore.isOffline()) {
context.errors = ConstantMessages.OfflineMessage;
return;
}
const context = this._storage.get('card-popup');

const comment = {
cid: context.cid,
Expand Down Expand Up @@ -1980,8 +1993,11 @@ class BoardStore extends BaseStore {
*/
async _updateCardComment(data) {
if (SettingsStore.isOffline()) {
this._storage.get('card-popup').errors = ConstantMessages.OfflineMessage;
return;
}
this._storage.get('card-popup').errors = null;

let payload;

try {
Expand Down Expand Up @@ -2074,10 +2090,11 @@ class BoardStore extends BaseStore {
* @private
*/
async _uploadAttachment(data) {
const cardContext = this._storage.get('card-popup');
if (SettingsStore.isOffline()) {
cardContext.errors = ConstantMessages.OfflineMessage;
return;
}
const cardContext = this._storage.get('card-popup');
cardContext.errors = null;
if (data.file.size > BoardStoreConstants.MaxAttachmentSize) {
cardContext.errors = ConstantMessages.AttachmentSizeTooBig;
Expand All @@ -2102,6 +2119,10 @@ class BoardStore extends BaseStore {
card.attachments.push(payload.data);
return;

case HttpStatusCodes.TooLarge:
cardContext.errors = ConstantMessages.TooLargeMessage;
return;

default:
cardContext.errors = ConstantMessages.UnsuccessfulRequest;
return;
Expand All @@ -2114,10 +2135,11 @@ class BoardStore extends BaseStore {
* @private
*/
async _deleteAttachment(data) {
const cardContext = this._storage.get('card-popup');
if (SettingsStore.isOffline()) {
cardContext.errors = ConstantMessages.OfflineMessage;
return;
}
const cardContext = this._storage.get('card-popup');

let payload;

Expand Down Expand Up @@ -2152,7 +2174,10 @@ class BoardStore extends BaseStore {
const attachment = cardContext.attachments.find((attach) => {
return attach.atid === data.atid;
});
window.open(attachment.file_tech_name, `Download: ${attachment.file_pub_name}`);
console.log('attachment.file_tech_name: ' + attachment.file_tech_name);
window.open(ServiceWorker.ATTACHMENT_PREFIX + attachment.file_tech_name +
`?${ServiceWorker.ATTACH_NAME_PARAM}=${attachment.file_pub_name}`,
`Download: ${attachment.file_pub_name}`);
}

/**
Expand Down Expand Up @@ -2385,12 +2410,13 @@ class BoardStore extends BaseStore {
* @param {Object} data данные c названием тега
*/
async _createTag(data) {
if (SettingsStore.isOffline()) {
return;
}
const contextTagPopUp = this._storage.get('tag-popup');
const contextTagListPopUp = this._storage.get('tags-list-popup');

if (SettingsStore.isOffline()) {
contextTagPopUp.errors = ConstantMessages.OfflineMessage;
return;
}
contextTagPopUp.errors = null;
const validator = new Validator();
contextTagPopUp.errors = validator.validateTagTitle(contextTagPopUp.tag_name);
Expand Down Expand Up @@ -2486,10 +2512,11 @@ class BoardStore extends BaseStore {
* Обновляет тег
*/
async _updateTag() {
const context = this._storage.get('tag-popup');
if (SettingsStore.isOffline()) {
context.errors = ConstantMessages.OfflineMessage;
return;
}
const context = this._storage.get('tag-popup');

context.errors = null;
const validator = new Validator();
Expand Down Expand Up @@ -2541,12 +2568,13 @@ class BoardStore extends BaseStore {
* @param {Object} data данные
*/
async _toggleTag(data) {
if (SettingsStore.isOffline()) {
return;
}
const context = this._storage.get('tags-list-popup');
const currentCard = this._getCardById(this._storage.get('card-popup').clid,
this._storage.get('card-popup').cid);
if (SettingsStore.isOffline()) {
context.errors = ConstantMessages.OfflineMessage;
return;
}

let payload;

Expand Down
Loading

0 comments on commit 44c0ab3

Please sign in to comment.