Skip to content

Commit

Permalink
the last awesome 2.0 series version
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeriolino committed Apr 15, 2019
1 parent ab99362 commit d56c1a4
Show file tree
Hide file tree
Showing 9 changed files with 381 additions and 102 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -65,6 +65,7 @@
"font-awesome": "^4.7.0",
"moment": "^2.18.1",
"socket.io-client": "^2.0.3",
"sortablejs": "^1.8.4",
"vue": "^2.6.9",
"vue-electron": "^1.0.6",
"vue-router": "^3.0.1",
Expand Down
185 changes: 112 additions & 73 deletions src/renderer/pages/Home.vue
Expand Up @@ -20,9 +20,9 @@
<section>
<p v-if="config.showSubitle">{{ 'home.departments.subtitle'|trans }}</p>
<div class="columns is-multiline is-mobile">
<div :class="columnClasses()" v-for="department in departments" :key="department.id">
<button type="button" class="button is-xlarge is-block" @click="selectDepartment(department)" :style="{'color': config.buttonFontColor,'background-color': config.buttonBgColor}">
{{department.nome}}
<div :class="columnClasses()" v-for="config in enabledDepartments" :key="config.department.id">
<button type="button" class="button is-xlarge is-block" @click="selectDepartment(config.department)" :style="buttonStyle(config)">
{{config.department.nome}}
</button>
</div>
</div>
Expand All @@ -43,9 +43,9 @@
<section>
<p v-if="config.showSubitle">{{ 'home.services.subtitle'|trans }}</p>
<div class="columns is-multiline is-mobile">
<div :class="columnClasses()" v-for="su in departmentServices" :key="su.servico.id">
<button type="button" class="button is-xlarge is-block" @click="selectService(su)" :style="{'color': config.buttonFontColor,'background-color': config.buttonBgColor}">
{{su.servico.nome}}
<div :class="columnClasses()" v-for="config in departmentServices" :key="config.servicoUnidade.servico.id">
<button type="button" class="button is-xlarge is-block" @click="selectService(config.servicoUnidade)" :style="buttonStyle(config)">
{{config.servicoUnidade.servico.nome}}
</button>
</div>
</div>
Expand Down Expand Up @@ -76,9 +76,9 @@
<section>
<p v-if="config.showSubitle">{{ 'home.services.subtitle'|trans }}</p>
<div class="columns is-multiline is-mobile">
<div :class="columnClasses()" v-for="su in enabledServices" :key="su.servico.id">
<button type="button" class="button is-xlarge is-block" @click="selectService(su)" :style="{'color': config.buttonFontColor,'background-color': config.buttonBgColor}">
{{su.servico.nome}}
<div :class="columnClasses()" v-for="config in enabledServices" :key="config.servicoUnidade.servico.id">
<button type="button" class="button is-xlarge is-block" @click="selectService(config.servicoUnidade)" :style="buttonStyle(config)">
{{config.servicoUnidade.servico.nome}}
</button>
</div>
</div>
Expand Down Expand Up @@ -304,7 +304,7 @@
}
}
function checkToken ($store) {
function checkToken (ctx, $store) {
clearTimeout(timeoutId)
if (!running) {
Expand All @@ -320,13 +320,14 @@
.dispatch('refresh')
.then(() => {
log('token refreshed')
ctx.fetchData()
}, e => {
log(e)
})
}
timeoutId = setTimeout(() => {
checkToken($store)
checkToken(ctx, $store)
}, 60 * 1000)
}
Expand Down Expand Up @@ -376,9 +377,9 @@
firstPage: 'allServices',
page: '',
enabledServices: [],
enabledDepartments: [],
servicoUnidade: null,
department: null,
departments: [],
departmentServices: [],
subservices: [],
priorities: [],
Expand Down Expand Up @@ -427,8 +428,8 @@
selectDepartment (department) {
this.page = 'department'
this.department = department
this.departmentServices = this.enabledServices.filter(su => {
return su.departamento && su.departamento.id === department.id
this.departmentServices = this.enabledServices.filter(s => {
return s.servicoUnidade.departamento && s.servicoUnidade.departamento.id === department.id
})
},
Expand Down Expand Up @@ -526,8 +527,85 @@
if (evt.keyCode === 81) {
this.showMenu = true
}
},
buttonStyle (config) {
config = (config || {})
let style = {
color: config.fontColor || this.config.buttonFontColor,
backgroundColor: config.bgColor || this.config.buttonBgColor
}
return style
},
fetchData () {
this.enabledDepartments = []
this.enabledServices = []
let promise = null
let promises = []
promise = this.$store.dispatch('fetchPriorities', this.config.unity).then((priorities) => {
this.priorities = priorities.filter((p) => {
return p.peso > 0
})
})
promises.push(promise)
// refreshing saved data
promise = this.$store.dispatch('fetchDepartments').then((departments) => {
this.config.departments.forEach(d => {
const config = JSON.parse(JSON.stringify(d))
if (config.enabled) {
config.departament = departments.filter((d2) => d2.id === config.department.id)[0]
if (config.departament) {
this.enabledDepartments.push(config)
}
}
})
})
promises.push(promise)
// refreshing saved data
promise = this.$store.dispatch('fetchServices', this.config.unity).then((services) => {
this.config.services.forEach(s => {
const config = JSON.parse(JSON.stringify(s))
if (config.enabled) {
const su = services.filter((s2) => s2.servico.id === config.servicoUnidade.servico.id)[0]
if (su) {
config.servicoUnidade = su
this.enabledServices.push(config)
}
}
})
})
promises.push(promise)
Promise.all(promises).then(() => {
if (this.enabledServices.length === 0) {
this.$router.push('/settings')
return
}
if (this.enabledServices.length > 1) {
if (this.config.groupByDepartments && this.enabledDepartments.length > 0) {
this.firstPage = 'departments'
} else {
this.firstPage = 'allServices'
}
} else {
this.firstPage = 'service'
this.servicoUnidade = this.enabledServices[0].servicoUnidade
}
this.begin()
})
}
},
mounted () {
document.querySelector('html').style.fontSize = (this.config.scale * 100) + '%'
},
beforeMount () {
connect(this, this.$store)
Expand All @@ -545,53 +623,10 @@
}
if (!running) {
running = true
checkToken(store)
checkToken(this, store)
}
store.dispatch('fetchServices', config.unity).then((services) => {
this.enabledServices = []
for (let j = 0; j < config.services.length; j++) {
let id = config.services[j]
for (let i = 0; i < services.length; i++) {
let su = services[i]
if (su.servico.id === id) {
this.enabledServices.push(su)
if (su.departamento) {
let contains = false
for (let k = 0; k < this.departments.length; k++) {
if (this.departments[k].id === su.departamento.id) {
contains = true
break
}
}
if (!contains) {
this.departments.push(su.departamento)
}
}
break
}
}
}
if (this.enabledServices.length > 1) {
if (config.departments) {
this.firstPage = 'departments'
} else {
this.firstPage = 'allServices'
}
} else {
this.firstPage = 'service'
this.servicoUnidade = this.enabledServices[0]
}
this.begin()
})
store.dispatch('fetchPriorities', config.unity).then((priorities) => {
this.priorities = priorities.filter((p) => {
return p.peso > 0
})
})
this.fetchData()
this.intervalId = setInterval(() => {
this.tick()
Expand All @@ -613,21 +648,25 @@
</script>

<style lang="sass">
#home .menu
#home
height: 100%
position: fixed
top: 2vh
left: 2vw
background-color: rgba(0,0,0,.5)
padding: 10px
border-radius: 8px
opacity: 0
z-index: 100
&:hover
opacity: 1
transition: opacity 0.2s ease-in-out
background-color: rgba(0,0,0,1)
a
color: #ffffff
width: 100%
.menu
position: fixed
top: 2vh
left: 2vw
background-color: rgba(0,0,0,.5)
padding: 10px
border-radius: 8px
opacity: 0
z-index: 100
&:hover
opacity: 1
transition: opacity 0.2s ease-in-out
background-color: rgba(0,0,0,1)
a
color: #ffffff
article
width: 100%
Expand Down

0 comments on commit d56c1a4

Please sign in to comment.