From 874f7b538f4ef742b510b3469cca36ba21395038 Mon Sep 17 00:00:00 2001 From: behmaram Date: Wed, 6 Jan 2021 13:50:38 +0330 Subject: [PATCH] fix:error handler and refactor:tooltip --- .../Global/components/Inputs/Slide-Button.vue | 30 ++++---- .../components/Inputs/TooltipButton.vue | 13 ++-- .../Global/services/errorHandler.services.js | 1 + .../js/Global/services/storage.services.js | 69 +++++++++++++++++-- 4 files changed, 92 insertions(+), 21 deletions(-) diff --git a/resources/js/Global/components/Inputs/Slide-Button.vue b/resources/js/Global/components/Inputs/Slide-Button.vue index 20c3ea8..7ecda81 100644 --- a/resources/js/Global/components/Inputs/Slide-Button.vue +++ b/resources/js/Global/components/Inputs/Slide-Button.vue @@ -1,16 +1,21 @@ \ No newline at end of file + diff --git a/resources/js/Global/services/errorHandler.services.js b/resources/js/Global/services/errorHandler.services.js index 4703607..580d3ac 100644 --- a/resources/js/Global/services/errorHandler.services.js +++ b/resources/js/Global/services/errorHandler.services.js @@ -39,6 +39,7 @@ function errorResponseHandler(error) { toast.error('مشکل از سمت سرور', 'خطا'); } } + return Promise.reject(error.response); } function successHandler(response) { if(response.status === 200 || response.status === 201) { diff --git a/resources/js/Global/services/storage.services.js b/resources/js/Global/services/storage.services.js index ae8b7c5..c2eb0d7 100644 --- a/resources/js/Global/services/storage.services.js +++ b/resources/js/Global/services/storage.services.js @@ -33,7 +33,7 @@ const CategoryNameService = { }, save(category_name = null) { - category_name = qs.stringify(category_name); + category_name = qs.stringify(category_name); localStorage.setItem(CATEGORYNAME, category_name) }, @@ -51,7 +51,7 @@ const UserService = { }, save(user = null) { - user = qs.stringify(user); + user = qs.stringify(user); localStorage.setItem(USER, user) }, @@ -69,7 +69,7 @@ const PermissionService = { }, save(permission = null) { - permission = qs.stringify(permission); + permission = qs.stringify(permission); localStorage.setItem(PERMISSION, permission) }, @@ -94,5 +94,66 @@ const VirtualActivityService = { localStorage.removeItem(PERMISSION) }, } +const Paginate = { -export { TokenService, UserService, PermissionService, VirtualActivityService, CategoryNameService } + get(SERVICE) { + if (localStorage.getItem(SERVICE)) { + let service = qs.parse(localStorage.getItem(SERVICE), { strictNullHandling: true }); + if (typeof service.pagination !== 'undefined' && service.pagination) { + let pagination = {}; + for(let key in service.pagination) { + pagination[key] = Number(service.pagination[key]) + } + return pagination + } + } + return null; + }, + + save(SERVICE, pagination = null ) { + let service = null; + if (localStorage.getItem(SERVICE)) { + service = qs.parse(localStorage.getItem(SERVICE)); + } else { + service = {}; + } + service['pagination'] = pagination; + let service_paginate = qs.stringify(service); + localStorage.setItem(SERVICE, service_paginate) + }, + + remove(SERVICE) { + this.save(SERVICE); + }, +}; + +const Sort = { + get(SERVICE) { + if (localStorage.getItem(SERVICE)) { + let service = qs.parse(localStorage.getItem(SERVICE), { strictNullHandling: true }); + if (typeof service.sort !== 'undefined' && service.sort) { + return service.sort + } + } + return null; + }, + + save(SERVICE, sort = '') { + let service = null; + if (localStorage.getItem(SERVICE)) { + service = qs.parse(localStorage.getItem(SERVICE)); + } else { + service = {}; + } + service['sort'] = sort; + let service_sort = qs.stringify(service); + localStorage.setItem(SERVICE, service_sort) + }, + + remove(SERVICE) { + this.save(SERVICE); + }, +}; + + +export { TokenService, UserService, PermissionService, VirtualActivityService, CategoryNameService, Paginate, Sort }