From 986e0ad5831012012269c4fe0637750e305b03e9 Mon Sep 17 00:00:00 2001 From: saeid_01 Date: Thu, 22 Aug 2019 10:33:47 +0430 Subject: [PATCH] delete gql --- public/mix-manifest.json | 10 ++-- resources/js/Global/mixins/api.js | 21 -------- resources/js/Global/mixins/global.js | 19 ++++++- resources/js/Global/mixins/modal.js | 17 ------- resources/js/Global/services/api.services.js | 18 +++++-- .../modules/common/actions.js} | 0 .../js/Global/store/modules/common/getters.js | 4 ++ .../Global/store/modules/common/mutations.js | 8 +++ .../js/Global/store/modules/common/state.js | 6 +++ resources/js/Global/utils/api/init/apollo.js | 26 ---------- .../js/Global/utils/api/request/apolloApi.js | 41 --------------- .../js/Global/utils/api/request/axiosApi.js | 51 ------------------- resources/js/Home/app.js | 4 +- 13 files changed, 58 insertions(+), 167 deletions(-) delete mode 100644 resources/js/Global/mixins/api.js delete mode 100644 resources/js/Global/mixins/modal.js rename resources/js/Global/{utils/api/init/axios.js => store/modules/common/actions.js} (100%) create mode 100644 resources/js/Global/store/modules/common/getters.js create mode 100644 resources/js/Global/store/modules/common/mutations.js create mode 100644 resources/js/Global/store/modules/common/state.js delete mode 100644 resources/js/Global/utils/api/init/apollo.js delete mode 100644 resources/js/Global/utils/api/request/apolloApi.js delete mode 100644 resources/js/Global/utils/api/request/axiosApi.js diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 61f84d3..857327e 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,7 +1,7 @@ { - "/js/vue/Authentication/app.js": "/js/vue/Authentication/app.js?id=46a300281c838d8eb317", - "/js/vue/Home/app.js": "/js/vue/Home/app.js?id=3b00321087e86fb5e1bf", - "/js/vue/Modules/CRM/app.js": "/js/vue/Modules/CRM/app.js?id=10e1114fa9d3880bcd52", - "/js/vue/Modules/Reservation/app.js": "/js/vue/Modules/Reservation/app.js?id=2619184b0d853d8273c1", - "/js/vue/User/app.js": "/js/vue/User/app.js?id=03d4dbc997cf4190dd65" + "/js/vue/Authentication/app.js": "/js/vue/Authentication/app.js?id=70376fdc43efc4b13789", + "/js/vue/Home/app.js": "/js/vue/Home/app.js?id=aa9935664046e6bbb8aa", + "/js/vue/Modules/CRM/app.js": "/js/vue/Modules/CRM/app.js?id=69daf7bd7d44517ffaaf", + "/js/vue/Modules/Reservation/app.js": "/js/vue/Modules/Reservation/app.js?id=8a8b1f6e787ca9a75d5b", + "/js/vue/User/app.js": "/js/vue/User/app.js?id=815ce96ae40cc8c7560c" } diff --git a/resources/js/Global/mixins/api.js b/resources/js/Global/mixins/api.js deleted file mode 100644 index 079c2ef..0000000 --- a/resources/js/Global/mixins/api.js +++ /dev/null @@ -1,21 +0,0 @@ -import axiosApi from '@Global/utils/api/request/axiosApi' -import apolloApi from '@Global/utils/api/request/apolloApi' - -export const api = (url) => { - let apiClass; - if (url['type'] == 'apollo') { - apiClass = new apolloApi (url); - } else if (url['type'] == 'axios') { - apiClass = new axiosApi (url); - } else { - throw 'parameter "' + url['type'] + '" must be axios or apollo.'; - } - - return apiClass.init(); -} - -export default { - methods: { - $_api: api - }, -} \ No newline at end of file diff --git a/resources/js/Global/mixins/global.js b/resources/js/Global/mixins/global.js index 1b8c867..20fbf5e 100644 --- a/resources/js/Global/mixins/global.js +++ b/resources/js/Global/mixins/global.js @@ -1,8 +1,25 @@ +import { mapActions, mapMutations } from "vuex"; const global = { methods: { $_getPath(subPath) { return '/' + subPath; - } + }, + + //Modal + + ...mapActions("modal", ["openModal", "closeModal", "dialog"]), + $_openModal(options) { + this.openModal(options); + }, + $_closeModal(options) { + this.closeModal(options); + }, + + //Alert + + $_dialog(options) { + this.dialog(options); + }, } }; diff --git a/resources/js/Global/mixins/modal.js b/resources/js/Global/mixins/modal.js deleted file mode 100644 index fd86743..0000000 --- a/resources/js/Global/mixins/modal.js +++ /dev/null @@ -1,17 +0,0 @@ -import { mapActions, mapGetters } from "vuex"; -const modal = { - methods: { - ...mapActions("modal", ["openModal", "closeModal", "dialog"]), - $_openModal(options) { - this.openModal(options); - }, - $_closeModal(options) { - this.closeModal(options); - }, - $_dialog(options) { - this.dialog(options); - } - }, -}; - -export { modal }; diff --git a/resources/js/Global/services/api.services.js b/resources/js/Global/services/api.services.js index cf3ff42..9015192 100644 --- a/resources/js/Global/services/api.services.js +++ b/resources/js/Global/services/api.services.js @@ -1,16 +1,28 @@ import axios from 'axios' import { TokenService } from './storage.services' - +import commonState from '@Global/store/modules/common/state'; const ApiService = { - init(baseURL) { - axios.defaults.baseURL = baseURL; + init(baseURL = null) { + if (baseURL) { + axios.defaults.baseURL = baseURL; + } + + axios.interceptors.request.use((config) => { + config.headers = this.setModuleHeader(config.headers); + return config; + }); }, setHeader() { axios.defaults.headers.common["Accept"] = `application/json`; axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; }, + + setModuleHeader(headers = axios.defaults.headers.common) { + headers['Module'] = commonState.current_module; + return headers; + }, setAuthHeader() { axios.defaults.headers.common["Authorization"] = `Bearer ${TokenService.getToken()}`; diff --git a/resources/js/Global/utils/api/init/axios.js b/resources/js/Global/store/modules/common/actions.js similarity index 100% rename from resources/js/Global/utils/api/init/axios.js rename to resources/js/Global/store/modules/common/actions.js diff --git a/resources/js/Global/store/modules/common/getters.js b/resources/js/Global/store/modules/common/getters.js new file mode 100644 index 0000000..868629c --- /dev/null +++ b/resources/js/Global/store/modules/common/getters.js @@ -0,0 +1,4 @@ +export default { + getCurrentModule: state => state.current_module, + getCurrentModuleInfo: state => state.current_module_info, +} \ No newline at end of file diff --git a/resources/js/Global/store/modules/common/mutations.js b/resources/js/Global/store/modules/common/mutations.js new file mode 100644 index 0000000..3e1f25c --- /dev/null +++ b/resources/js/Global/store/modules/common/mutations.js @@ -0,0 +1,8 @@ +export default { + SET_CURRENT_MODULE(state, module) { + state.current_module = module; + }, + SET_CURRENT_MODULE_INFO(state, moduleInfo) { + state.current_module_info = moduleInfo; + } +}; diff --git a/resources/js/Global/store/modules/common/state.js b/resources/js/Global/store/modules/common/state.js new file mode 100644 index 0000000..6374d46 --- /dev/null +++ b/resources/js/Global/store/modules/common/state.js @@ -0,0 +1,6 @@ +export default { + current_module: "", + current_module_info: { + name: "" + } +}; diff --git a/resources/js/Global/utils/api/init/apollo.js b/resources/js/Global/utils/api/init/apollo.js deleted file mode 100644 index eaeb6bb..0000000 --- a/resources/js/Global/utils/api/init/apollo.js +++ /dev/null @@ -1,26 +0,0 @@ -import { ApolloClient } from 'apollo-client'; -import { createHttpLink } from 'apollo-link-http'; -import { setContext } from 'apollo-link-context'; -import { InMemoryCache } from 'apollo-cache-inmemory'; -import { TokenService } from "@Global/services/storage.services"; - -const httpLink = createHttpLink({ - uri: '/graphql', -}); - - -const authLink = setContext((_, { headers }) => { - // return the headers to the context so httpLink can read them - return { - headers: { - ...headers, - authorization: TokenService.getToken() ? `Bearer ${TokenService.getToken()}` : "", - } - } -}); - -export default new ApolloClient({ - link: authLink.concat(httpLink), - cache: new InMemoryCache(), -}); - diff --git a/resources/js/Global/utils/api/request/apolloApi.js b/resources/js/Global/utils/api/request/apolloApi.js deleted file mode 100644 index 53bffc8..0000000 --- a/resources/js/Global/utils/api/request/apolloApi.js +++ /dev/null @@ -1,41 +0,0 @@ -import apollo from "@Global/utils/api/init/apollo"; - -export default class apolloApi { - - constructor(urlObj) { - this.staticMethods = ["query", "mutate"]; - - this.method = urlObj.method; - this.gql = urlObj.gql; - this.variables = urlObj.data; - } - - init() { - if (this.checkMethod()) { - return this[this.method](); - } - } - - checkMethod() { - return this.staticMethods.includes(this.method); - } - - query() { - let query = this.gql; - let variables = this.variables; - - return apollo.query({ - query, - variables - }); - } - - mutate() { - const mutation = this.gql; - const variables = this.variables; - return apollo.mutate({ - mutation, - variables - }); - } -} diff --git a/resources/js/Global/utils/api/request/axiosApi.js b/resources/js/Global/utils/api/request/axiosApi.js deleted file mode 100644 index 5ed3a16..0000000 --- a/resources/js/Global/utils/api/request/axiosApi.js +++ /dev/null @@ -1,51 +0,0 @@ -import axios from "axios"; -import { urlGenerator } from '@Global/services/url.service.js'; - -export default class axiosApi { - - constructor(urlObj) { - this.staticMethods = ["get", "post", "put", "delete"]; - this.baseURL = '/'; - - this.method = urlObj.method; - this.url = urlGenerator(urlObj.url, urlObj.data); - console.log(this.url); - - this.data = urlObj.data; - } - - init() { - axios.defaults.baseURL = this.baseURL; - - if (this.checkMethod()) { - return this[this.method](); - } - } - - checkMethod() { - return this.staticMethods.includes(this.method); - } - - get() { - const params = this.data; - return axios.get(this.url, { - params - }); - } - - post() { - return axios.post(this.url, this.data); - } - - put() { - const data = this.data; - data['_method'] = 'put'; - return axios.put(this.url, data); - } - - delete() { - const data = this.data; - data['_method'] = 'delete'; - return axios.put(this.url, data); - } -} diff --git a/resources/js/Home/app.js b/resources/js/Home/app.js index bf650a6..4a3ec79 100644 --- a/resources/js/Home/app.js +++ b/resources/js/Home/app.js @@ -5,7 +5,6 @@ import store from './store' import VueScrollReveal from 'vue-scroll-reveal' import Vuetify from 'vuetify' import { global } from "@Global/mixins/global"; -import { modal } from "@Global/mixins/modal"; import { commingSoon } from "@Global/mixins/commingSoon"; import 'popper.js' @@ -79,12 +78,13 @@ Vue.use(VueScrollReveal, { mobile: false }); Vue.mixin({ - methods: { ...global["methods"], ...modal["methods"], ...commingSoon["methods"] } + methods: { ...global["methods"], ...commingSoon["methods"] } }); import { TokenService } from "@Global/services/storage.services"; import ApiService from "@Global/services/api.services"; // If token exists set Authorizion header +ApiService.init(); if (TokenService.getToken()) { ApiService.setAuthHeader(); }