Skip to content

Commit

Permalink
fix: persistent scan log
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Dec 24, 2020
1 parent 5b6d4ed commit 32b4841
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
25 changes: 17 additions & 8 deletions pages/scan.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export default {
data() {
return {
routerProcess: false,
log: [],
running: '',
available: '',
pending: '',
Expand All @@ -125,6 +124,10 @@ export default {
},
computed: {
log(){
return this.$store.state.log;
},
url: {
get() {
return this.$store.state.url;
Expand Down Expand Up @@ -160,6 +163,12 @@ export default {
},
methods: {
logPush(msg) {
const log = [...this.log, ...[msg]];
if (log.length > 10000) log.shift();
this.$store.commit('log', log);
},
// form state to GET params
updateUrlQuery(push = false) {
if (this.routerProcess) return;
Expand Down Expand Up @@ -193,7 +202,7 @@ export default {
},
async sendTask() {
this.log.splice(0, this.log.length);
this.$store.commit('log', []); // clear log
const opts = {
url: this.url,
args: this.args
Expand All @@ -220,11 +229,11 @@ export default {
// log to "terminal"
this.socket.on("status" + key, (msg, cb) => {
console.log(`msg ${key}: ${msg}`);
this.log.push(msg);
this.logPush(msg);
});
this.socket.on("status", (msg, cb) => {
console.log('msg: ', msg);
this.log.push(msg);
this.logPush(msg);
});
// server queue info
Expand All @@ -241,7 +250,7 @@ export default {
const viewerUrl = window.location.origin + this.$router.options.base;
if (data.json) {
const url = viewerUrl + '?url=' + data.json;
this.log.push(`result: <a href="${url}">${url}</a>`);
this.logPush(`result: <a href="${url}">${url}</a>`);
this.$store.commit('itemsJsonUrl', data.json);
}
if (data.name) {
Expand All @@ -252,7 +261,7 @@ export default {
}
const jsonUrl = `${baseUrl}/${data.name}`;
const url = `${viewerUrl}?url=${jsonUrl}`;
this.log.push(`result: <a href="${url}">${url}</a>`);
this.logPush(`result: <a href="${url}">${url}</a>`);
this.$store.commit('itemsJsonUrl', jsonUrl);
}
});
Expand All @@ -274,13 +283,13 @@ export default {
});
this.socket.on("disconnect", () => {
this.log.push('server disconnected');
this.logPush('server disconnected');
this.isNeedAuth = true;
this.running = '';
});
this.socket.on("reconnect_attempt", () => {
this.log.push('try to connect ' + this.serverUrl + '...');
this.logPush('try to connect ' + this.serverUrl + '...');
});
firebase.auth().onAuthStateChanged(user => {
Expand Down
3 changes: 2 additions & 1 deletion plugins/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default ({store}) => {
'uid',
'url',
'args',
'serverUrl'],
'serverUrl',
'log'],
})(store);
};
4 changes: 4 additions & 0 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const state = () => ({
url: 'https://blog.popstas.ru',
args: '-m 50',
serverUrl: process.env.SERVER_URL || false,
log: [],

introTourSteps: [ // tolang
/* {
Expand Down Expand Up @@ -442,6 +443,9 @@ export const mutations = {
serverUrl(state, newValue) {
state.serverUrl = newValue;
},
log(state, newValue) {
state.log = newValue;
},
};

export const actions = {
Expand Down

0 comments on commit 32b4841

Please sign in to comment.