From f69e28a09735203548e093d933b2b1f6ce1cb860 Mon Sep 17 00:00:00 2001 From: Stanislav Popov Date: Mon, 24 Jun 2019 13:46:33 +0500 Subject: [PATCH] =?UTF-8?q?fix:=20ajaxData=20->=20updateData,=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B1=D0=B5=D0=B7=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B2?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Entry.vue | 5 ++- pages/index.vue | 78 ++++++++++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/components/Entry.vue b/components/Entry.vue index 5c154be..88c2221 100644 --- a/components/Entry.vue +++ b/components/Entry.vue @@ -27,7 +27,7 @@ width: 2rem; } .entry__second { - margin-left: 2rem; + margin-left: 2.3rem; } .entry__project { } @@ -65,8 +65,11 @@ export default { computed: { duration() { // normal entry + // console.log('entry: ', this.entry); if (this.entry.dur > 0) return Math.round(this.entry.dur / 1000 / 60); + if (this.entry.dur === 0) return 0; + // running entry const seconds = Math.round(this.entry.dur + this.currentTickTime / 1000); const t = { diff --git a/pages/index.vue b/pages/index.vue index 16f7981..fc47a15 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -45,39 +45,11 @@ let apiUrl = store.state.apiUrl; try { asyncData = { - entries: { - current: [await app.$axios.$get(apiUrl + '/toggl/entries/current')], - today: await app.$axios.$get(apiUrl + '/toggl/entries', {params: {type: 'today'}}), - pending: await app.$axios.$get(apiUrl + '/toggl/entries', {params: {type: 'pending'}}), - last: await app.$axios.$get(apiUrl + '/toggl/entries', {params: {type: 'last'}}), - } }; - if(asyncData.entries.current[0].id == 0){ - asyncData.entries.current = []; - } - - // sort by date desc - asyncData.entries.today.sort((a, b) => b.id - a.id); - asyncData.entries.pending.sort((a, b) => b.id - a.id); - asyncData.entries.last.sort((a, b) => b.id - a.id); - - asyncData.tabs = [ - {label: 'Сейчас', props: {entries: asyncData.entries.current}}, - {label: 'Сегодня', props: {entries: asyncData.entries.today}}, - {label: 'Ожидают', props: {entries: asyncData.entries.pending}}, - {label: 'Неделя', props: {entries: asyncData.entries.last}}, - ]; - // let analitics = await app.$axios.$get(apiUrl + '/planfix/analitics'); // store.commit('analitics', analitics.Analitics); - asyncData.pages = [ - {name: 'Записи', page: EntriesTabsPage}, - {name: 'Настройки', page: SettingsPage}, - ]; - - store.commit('tabs', asyncData.tabs); } catch (e) { console.log('error while get data'); @@ -104,6 +76,28 @@ this.$store.commit('tabs', tabs); }, + async updateData() { + this.entries = this.entries || { current: [], today: [], pending: [], last: [] }; + + this.entries.current = [await this.$axios.$get(this.$store.state.apiUrl + '/toggl/entries/current')]; + this.entries.today = await this.$axios.$get(this.$store.state.apiUrl + '/toggl/entries', {params: {type: 'today'}}); + this.entries.pending = await this.$axios.$get(this.$store.state.apiUrl + '/toggl/entries', {params: {type: 'pending'}}); + this.entries.last = await this.$axios.$get(this.$store.state.apiUrl + '/toggl/entries', {params: {type: 'last'}}); + + // check for empty current + // console.log('this.entries.current: ', this.entries.current); + if(this.entries.current[0].id == 0){ + this.entries.current = []; + } + + // sort by date desc + this.entries.today.sort((a, b) => b.id - a.id); + this.entries.pending.sort((a, b) => b.id - a.id); + this.entries.last.sort((a, b) => b.id - a.id); + + this.updateTabs(); + }, + setUpdateIntervals(currentTimeout, otherTimeout) { clearInterval(this.currentInterval); clearInterval(this.otherInterval); @@ -118,15 +112,31 @@ this.otherInterval = setInterval(async () => { // console.log('other data'); // console.log(new Date()); - this.entries.today = await app.$axios.$get(apiUrl + '/toggl/entries', {params: {type: 'today'}}); - this.entries.pending = await app.$axios.$get(apiUrl + '/toggl/entries', {params: {type: 'pending'}}); - this.entries.last = await app.$axios.$get(apiUrl + '/toggl/entries', {params: {type: 'last'}}); + this.entries.today = await this.$axios.$get(this.$store.state.apiUrl + '/toggl/entries', {params: {type: 'today'}}); + this.entries.pending = await this.$axios.$get(this.$store.state.apiUrl + '/toggl/entries', {params: {type: 'pending'}}); + this.entries.last = await this.$axios.$get(this.$store.state.apiUrl + '/toggl/entries', {params: {type: 'last'}}); + // console.log('this.entries: ', this.entries); this.updateTabs(); }, otherTimeout); } }, created() { // console.log('created'); + + this.pages = [ + {name: 'Записи', page: EntriesTabsPage}, + {name: 'Настройки', page: SettingsPage}, + ]; + + const tabs = [ + {label: 'Сейчас', props: {entries: []}}, + {label: 'Сегодня', props: {entries: []}}, + {label: 'Ожидают', props: {entries: []}}, + {label: 'Неделя', props: {entries: []}}, + ]; + this.$store.commit('tabs', tabs); + + this.updateData(); this.setUpdateIntervals(10000, 600000); }, @@ -134,12 +144,16 @@ // console.log('idle'); this.setUpdateIntervals(300000, 1800000); }, - onActive() { + + async onActive() { // console.log('active'); + + this.updateData(); this.setUpdateIntervals(10000, 600000); }, head() { + if (!this.entries.current) return 'planfix-toggl'; return { title: `${this.entries.current[0].description} - planfix-toggl` }; } }