Code clean-up: Rename alert to notify

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2019-11-16 23:55:56 +01:00
parent aebbb17a53
commit 2c3d6070cc
20 changed files with 101 additions and 107 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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);
});

View file

@ -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;

View file

@ -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);

View file

@ -89,7 +89,7 @@
</v-list-tile-content>
</v-list-tile>
<v-list-tile @click.stop="$alert.warning('Work in progress')">
<v-list-tile @click.stop="$notify.warning('Work in progress')">
<v-list-tile-content>
<v-list-tile-title>Work in progress...</v-list-tile-title>
</v-list-tile-content>

View file

@ -1,6 +1,6 @@
<template>
<v-snackbar
id="p-alert"
id="p-notify"
v-model="visible"
:color="color"
:timeout="0"
@ -23,7 +23,7 @@
import Event from 'pubsub-js';
export default {
name: 'p-alert',
name: 'p-notify',
data() {
return {
text: '',
@ -37,13 +37,13 @@
};
},
created() {
this.subscriptionId = Event.subscribe('alert', this.handleAlertEvent);
this.subscriptionId = Event.subscribe('notify', this.eventHandler);
},
destroyed() {
Event.unsubscribe(this.subscriptionId);
},
methods: {
handleAlertEvent: function (ev, data) {
eventHandler: function (ev, data) {
const type = ev.split('.')[1];
// get message from data object
@ -92,9 +92,15 @@
this.lastMessageId++;
this.lastMessage = message;
const alert = {'id': this.lastMessageId, 'color': color, 'textColor': textColor, 'delay': delay, 'msg': message};
const m = {
'id': this.lastMessageId,
'color': color,
'textColor': textColor,
'delay': delay,
'msg': message
};
this.messages.push(alert);
this.messages.push(m);
if(!this.visible) {
this.show();

View file

@ -102,9 +102,8 @@
</div>
</template>
<script>
import Event from "pubsub-js";
import Api from "common/api";
import Alert from "common/alert";
import Notify from "common/notify";
export default {
name: 'p-photo-clipboard',
@ -126,59 +125,44 @@
this.expanded = false;
},
batchPrivate() {
Event.publish("ajax.start");
const ctx = this;
Api.post("batch/photos/private", {"ids": this.selection}).then(function () {
Event.publish("ajax.end");
Alert.success("Toggled private flag");
Notify.success("Toggled private flag");
ctx.clearClipboard();
ctx.refresh();
}).catch(() => {
Event.publish("ajax.end");
});
},
batchStory() {
Event.publish("ajax.start");
const ctx = this;
Api.post("batch/photos/story", {"ids": this.selection}).then(function () {
Event.publish("ajax.end");
Alert.success("Toggled story flag");
Notify.success("Toggled story flag");
ctx.clearClipboard();
ctx.refresh();
}).catch(() => {
Event.publish("ajax.end");
});
},
batchDelete() {
this.dialog.delete = false;
Event.publish("ajax.start");
const ctx = this;
Api.post("batch/photos/delete", {"ids": this.selection}).then(function () {
Event.publish("ajax.end");
Alert.success("Photos deleted");
Notify.success("Photos deleted");
ctx.clearClipboard();
ctx.refresh();
}).catch(() => {
Event.publish("ajax.end");
});
},
batchTag() {
Alert.warning("Not implemented yet");
Notify.warning("Not implemented yet");
this.expanded = false;
},
batchAlbum() {
Alert.warning("Not implemented yet");
Notify.warning("Not implemented yet");
this.expanded = false;
},
batchDownload() {
Alert.warning("Not implemented yet");
Notify.warning("Not implemented yet");
this.expanded = false;
},
openDocs() {

View file

@ -147,7 +147,7 @@
this.scrollDisabled = (response.models.length < this.pageSize);
if (this.scrollDisabled) {
this.$alert.info('All ' + this.results.length + ' albums loaded');
this.$notify.info('All ' + this.results.length + ' albums loaded');
}
});
},
@ -201,9 +201,9 @@
this.scrollDisabled = (response.models.length < this.pageSize);
if (this.scrollDisabled) {
this.$alert.info(this.results.length + ' albums found');
this.$notify.info(this.results.length + ' albums found');
} else {
this.$alert.info('More than 20 albums found');
this.$notify.info('More than 20 albums found');
this.$nextTick(() => this.$emit("scrollRefresh"));
}
@ -222,7 +222,7 @@
const album = new Album({"AlbumName": name});
album.save().then(() => {
this.$alert.success(name + " created");
this.$notify.success(name + " created");
this.filter.q = "";
this.lastFilter = {};

View file

@ -143,7 +143,7 @@
this.scrollDisabled = (response.models.length < this.pageSize);
if (this.scrollDisabled) {
this.$alert.info('All ' + this.results.length + ' labels loaded');
this.$notify.info('All ' + this.results.length + ' labels loaded');
}
});
},
@ -197,9 +197,9 @@
this.scrollDisabled = (response.models.length < this.pageSize);
if (this.scrollDisabled) {
this.$alert.info(this.results.length + ' labels found');
this.$notify.info(this.results.length + ' labels found');
} else {
this.$alert.info('More than 20 labels found');
this.$notify.info('More than 20 labels found');
this.$nextTick(() => this.$emit("scrollRefresh"));
}

View file

@ -27,7 +27,7 @@
</template>
<script>
import Alert from "common/alert";
import Notify from "common/notify";
import Event from "pubsub-js";
export default {
@ -58,7 +58,7 @@
ctx.completed = 100;
ctx.fileName = '';
}).catch(function () {
Alert.error("Import failed");
Notify.error("Import failed");
ctx.busy = false;
ctx.completed = 0;
ctx.fileName = '';

View file

@ -27,7 +27,7 @@
</template>
<script>
import Alert from "common/alert";
import Notify from "common/notify";
import Event from "pubsub-js";
export default {
@ -58,7 +58,7 @@
ctx.completed = 100;
ctx.fileName = '';
}).catch(function () {
Alert.error("Indexing failed");
Notify.error("Indexing failed");
ctx.busy = false;
ctx.completed = 0;
ctx.fileName = '';

View file

@ -29,9 +29,8 @@
</template>
<script>
import Event from "pubsub-js";
import Api from "common/api";
import Alert from "common/alert";
import Notify from "common/notify";
export default {
name: 'p-tab-upload',
@ -68,9 +67,8 @@
return
}
Alert.info("Uploading photos...");
Event.publish("ajax.start");
Notify.info("Uploading photos...");
Notify.ajaxStart();
async function performUpload(ctx) {
for (let i = 0; i < ctx.selected.length; i++) {
@ -91,7 +89,7 @@
).then(function () {
ctx.completed = Math.round((ctx.current / ctx.total) * 100);
}).catch(function () {
Alert.error("Upload failed");
Notify.error("Upload failed");
});
}
}
@ -101,16 +99,16 @@
const ctx = this;
Api.post('import/upload/' + this.started).then(function () {
Alert.success("Upload complete");
Notify.success("Upload complete");
ctx.busy = false;
ctx.indexing = false;
}).catch(function () {
Alert.error("Failure while importing uploaded files");
Notify.error("Failure while importing uploaded files");
ctx.busy = false;
ctx.indexing = false;
});
Event.publish("ajax.end");
Notify.ajaxEnd();
});
},
}

View file

@ -120,7 +120,7 @@
this.scrollDisabled = (response.models.length < this.pageSize);
if (this.scrollDisabled) {
this.$alert.info('All ' + this.results.length + ' photos loaded');
this.$notify.info('All ' + this.results.length + ' photos loaded');
}
});
},
@ -182,9 +182,9 @@
this.scrollDisabled = (response.models.length < this.pageSize);
if (this.scrollDisabled) {
this.$alert.info(this.results.length + ' photos found');
this.$notify.info(this.results.length + ' photos found');
} else {
this.$alert.info('More than 50 photos found');
this.$notify.info('More than 50 photos found');
this.$nextTick(() => this.$emit("scrollRefresh"));
}

View file

@ -82,14 +82,14 @@
this.search();
},
currentPositionError(error) {
this.$alert.warning(error.message);
this.$notify.warning(error.message);
},
currentPosition() {
if ("geolocation" in navigator) {
this.$alert.success('Finding your position...');
this.$notify.success('Finding your position...');
navigator.geolocation.getCurrentPosition(this.currentPositionSuccess, this.currentPositionError);
} else {
this.$alert.warning('Geolocation is not available');
this.$notify.warning('Geolocation is not available');
}
},
formChange() {
@ -156,7 +156,7 @@
}
if (photos.length === 0) {
this.$alert.warning('No locations found');
this.$notify.warning('No locations found');
return;
}
@ -169,9 +169,9 @@
});
if (photos.length > 100) {
this.$alert.info('More than 100 photos found');
this.$notify.info('More than 100 photos found');
} else {
this.$alert.info(photos.length + ' photos found');
this.$notify.info(photos.length + ' photos found');
}
},
updateQuery() {
@ -206,7 +206,7 @@
Photo.search(params).then(response => {
if (!response.models.length) {
this.$alert.warning('No photos found');
this.$notify.warning('No photos found');
return;
}

View file

@ -57,7 +57,7 @@
},
save() {
this.settings.save().then(() => {
this.$alert.info("Settings saved");
this.$notify.info("Settings saved");
})
},
},

View file

@ -2,7 +2,7 @@
<div id="photoprism">
<p-loading-bar height="4"></p-loading-bar>
<p-alert></p-alert>
<p-notify></p-notify>
<v-app>
<p-navigation></p-navigation>

View file

@ -1,32 +1,32 @@
import Alert from "common/alert";
import Notify from "common/notify";
let sinon = require("sinon");
describe("common/alert", () => {
it("should call alert.info", () => {
let spy = sinon.spy(Alert, "info");
Alert.info("message");
let spy = sinon.spy(Notify, "info");
Notify.info("message");
sinon.assert.calledOnce(spy);
spy.resetHistory();
});
it("should call alert.warning", () => {
let spy = sinon.spy(Alert, "warning");
Alert.warning("message");
let spy = sinon.spy(Notify, "warning");
Notify.warning("message");
sinon.assert.calledOnce(spy);
spy.resetHistory();
});
it("should call alert.error", () => {
let spy = sinon.spy(Alert, "error");
Alert.error("message");
let spy = sinon.spy(Notify, "error");
Notify.error("message");
sinon.assert.calledOnce(spy);
spy.resetHistory();
});
it("should call alert.success", () => {
let spy = sinon.spy(Alert, "success");
Alert.success("message");
let spy = sinon.spy(Notify, "success");
Notify.success("message");
sinon.assert.calledOnce(spy);
spy.resetHistory();
});
});
});

View file

@ -30,7 +30,7 @@ func wsReader(ws *websocket.Conn) {
func wsWriter(ws *websocket.Conn, conf *config.Config) {
pingTicker := time.NewTicker(10 * time.Second)
s := event.Subscribe("index.*", "upload.*", "import.*", "alert.*", "config.*")
s := event.Subscribe("notify.*", "index.*", "upload.*", "import.*", "config.*")
defer func() {
pingTicker.Stop()

View file

@ -26,22 +26,22 @@ func SharedHub() *Hub {
func Error(msg string) {
log.Error(msg)
Publish("alert.error", Data{"msg": msg})
Publish("notify.error", Data{"msg": msg})
}
func Success(msg string) {
log.Info(msg)
Publish("alert.success", Data{"msg": msg})
Publish("notify.success", Data{"msg": msg})
}
func Info(msg string) {
log.Info(msg)
Publish("alert.info", Data{"msg": msg})
Publish("notify.info", Data{"msg": msg})
}
func Warning(msg string) {
log.Warn(msg)
Publish("alert.warning", Data{"msg": msg})
Publish("notify.warning", Data{"msg": msg})
}
func Publish (event string, data Data) {