diff --git a/frontend/src/app.js b/frontend/src/app.js index 2ac4e4e5c..40b26d565 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -1,5 +1,5 @@ import Api from "common/api"; -import Alert from "common/alert"; +import Notify from "common/notify"; import Config from "common/config"; import Clipboard from "common/clipboard"; import Components from "component/components"; @@ -30,7 +30,7 @@ const isPublic = config.getValue("public"); // Assign helpers to VueJS prototype Vue.prototype.$event = Event; -Vue.prototype.$alert = Alert; +Vue.prototype.$notify = Notify; Vue.prototype.$viewer = viewer; Vue.prototype.$session = Session; Vue.prototype.$api = Api; diff --git a/frontend/src/common/alert.js b/frontend/src/common/alert.js deleted file mode 100644 index b84a8475c..000000000 --- a/frontend/src/common/alert.js +++ /dev/null @@ -1,18 +0,0 @@ -import Event from "pubsub-js"; - -const Alert = { - info: function (message) { - Event.publish("alert.info", {msg: message}); - }, - warning: function (message) { - Event.publish("alert.warning", {msg: message}); - }, - error: function (message) { - Event.publish("alert.error", {msg: message}); - }, - success: function (message) { - Event.publish("alert.success", {msg: message}); - }, -}; - -export default Alert; diff --git a/frontend/src/common/api.js b/frontend/src/common/api.js index 09e29c057..8ec18c1ec 100644 --- a/frontend/src/common/api.js +++ b/frontend/src/common/api.js @@ -1,9 +1,8 @@ import "@babel/polyfill/noConflict"; -import axios from "axios"; -import Event from "pubsub-js"; -import Alert from "common/alert"; +import Axios from "axios"; +import Notify from "common/notify"; -const Api = axios.create({ +const Api = Axios.create({ baseURL: "/api/v1", headers: {common: { "X-Session-Token": window.localStorage.getItem("session_token"), @@ -12,7 +11,7 @@ const Api = axios.create({ Api.interceptors.request.use(function (config) { // Do something before request is sent - Event.publish("ajax.start", config); + Notify.ajaxStart(); return config; }, function (error) { // Do something with request error @@ -20,9 +19,11 @@ Api.interceptors.request.use(function (config) { }); Api.interceptors.response.use(function (response) { - Event.publish("ajax.end", response); + Notify.ajaxEnd(); return response; }, function (error) { + Notify.ajaxEnd(); + if(console && console.log) { console.log(error); } @@ -36,8 +37,7 @@ Api.interceptors.response.use(function (response) { errorMessage = data.message ? data.message : data.error; } - Event.publish("ajax.end"); - Alert.error(errorMessage); + Notify.error(errorMessage); return Promise.reject(error); }); diff --git a/frontend/src/common/notify.js b/frontend/src/common/notify.js new file mode 100644 index 000000000..b3cce9938 --- /dev/null +++ b/frontend/src/common/notify.js @@ -0,0 +1,24 @@ +import Event from "pubsub-js"; + +const Notify = { + info: function (message) { + Event.publish("notify.info", {msg: message}); + }, + warning: function (message) { + Event.publish("notify.warning", {msg: message}); + }, + error: function (message) { + Event.publish("notify.error", {msg: message}); + }, + success: function (message) { + Event.publish("notify.success", {msg: message}); + }, + ajaxStart: function() { + Event.publish("ajax.start"); + }, + ajaxEnd: function() { + Event.publish("ajax.end"); + } +}; + +export default Notify; diff --git a/frontend/src/component/components.js b/frontend/src/component/components.js index 34b384bc0..f2e9ab7ed 100644 --- a/frontend/src/component/components.js +++ b/frontend/src/component/components.js @@ -1,4 +1,4 @@ -import PAlert from "./p-alert.vue"; +import PNotify from "./p-notify.vue"; import PNavigation from "./p-navigation.vue"; import PLoadingBar from "./p-loading-bar.vue"; import PPhotoDetails from "./p-photo-details.vue"; @@ -13,7 +13,7 @@ import PScrollTop from "./p-scroll-top.vue"; const components = {}; components.install = (Vue) => { - Vue.component("p-alert", PAlert); + Vue.component("p-notify", PNotify); Vue.component("p-navigation", PNavigation); Vue.component("p-loading-bar", PLoadingBar); Vue.component("p-photo-details", PPhotoDetails); diff --git a/frontend/src/component/p-navigation.vue b/frontend/src/component/p-navigation.vue index 0c6b47a1d..a08ec24d9 100644 --- a/frontend/src/component/p-navigation.vue +++ b/frontend/src/component/p-navigation.vue @@ -89,7 +89,7 @@ - + Work in progress... diff --git a/frontend/src/component/p-alert.vue b/frontend/src/component/p-notify.vue similarity index 87% rename from frontend/src/component/p-alert.vue rename to frontend/src/component/p-notify.vue index a76af8955..fed35532d 100644 --- a/frontend/src/component/p-alert.vue +++ b/frontend/src/component/p-notify.vue @@ -1,6 +1,6 @@