Cleaning Code, moving functions...

This commit is contained in:
Paolo Arena
2019-03-22 18:49:38 +01:00
parent dd695a7ce5
commit 4d32467eb1
10 changed files with 49 additions and 99 deletions

View File

@@ -403,13 +403,13 @@ export default class SingleTodo extends Vue {
this.iconCompleted = 'check_circle_outline'
}
if (this.itemtodo.priority === tools.Todos.PRIORITY_HIGH) {
if (this.itemtodo.priority === tools.Priority.PRIORITY_HIGH) {
this.iconPriority = 'expand_less'
} // expand_less
else if (this.itemtodo.priority === tools.Todos.PRIORITY_NORMAL) {
else if (this.itemtodo.priority === tools.Priority.PRIORITY_NORMAL) {
this.iconPriority = 'remove'
}
else if (this.itemtodo.priority === tools.Todos.PRIORITY_LOW) {
else if (this.itemtodo.priority === tools.Priority.PRIORITY_LOW) {
this.iconPriority = 'expand_more'
} // expand_more

View File

@@ -9,12 +9,6 @@ export const allTables = ['todos', 'categories', 'sync_post_todos', 'sync_patch_
export const LIST_START = '0'
export const Priority = {
PRIORITY_HIGH: 2,
PRIORITY_NORMAL: 1,
PRIORITY_LOW: 0
}
export const DB = {
CMD_SYNC: 'sync-',
CMD_SYNC_NEW: 'sync-new-',
@@ -24,7 +18,7 @@ export const DB = {
TABLE_DELETE: 'delete_'
}
export async function dbInsertSave(call, item, method) {
async function dbInsertSave(call, item, method) {
let ret = true
if (!('serviceWorker' in navigator)) {
@@ -57,7 +51,7 @@ export async function dbInsertSave(call, item, method) {
return ret
}
export async function dbDeleteItem(call, item) {
async function dbDeleteItem(call, item) {
if (!('serviceWorker' in navigator)) {
// console.log('dbdeleteItem', item)
@@ -81,7 +75,7 @@ export async function dbDeleteItem(call, item) {
}
}
export async function Sync_Execute(cmd, table, method, item: ITodo, id, msg: String) {
async function Sync_Execute(cmd, table, method, item: ITodo, id, msg: String) {
// Send to Server to Sync
// console.log('Sync_Execute', cmd, table, method, item.descr, id, msg)
@@ -131,7 +125,7 @@ export async function Sync_Execute(cmd, table, method, item: ITodo, id, msg: Str
}
}
export async function Sync_ExecuteCmd(cmd, nametab: string, table, method, item: ITodo, id, msg: String) {
async function Sync_ExecuteCmd(cmd, nametab: string, table, method, item: ITodo, id, msg: String) {
// Send to Server to Sync
console.log('Sync_Execute', cmd, table, method, item.descr, id, msg)
@@ -187,7 +181,7 @@ export async function aftercalling(ris, checkPending: boolean, nametabindex: str
}
}
export async function checkPendingMsg() {
async function checkPendingMsg() {
// console.log('checkPendingMsg')
const config = await globalroutines(null, 'read', 'config', null, '1')
@@ -226,7 +220,7 @@ export async function checkPendingMsg() {
}
// If something in the call of Service Worker went wrong (Network or Server Down), then retry !
export async function sendSwMsgIfAvailable() {
async function sendSwMsgIfAvailable() {
let something = false
if ('serviceWorker' in navigator) {
@@ -273,7 +267,7 @@ export async function sendSwMsgIfAvailable() {
})
}
export async function waitAndRefreshData() {
async function waitAndRefreshData() {
return await Todos.actions.dbLoadTodo({ checkPending: false })
}
@@ -299,7 +293,7 @@ export async function waitAndcheckPendingMsg() {
})
}
export async function updatefromIndexedDbToStateTodo(nametab) {
async function updatefromIndexedDbToStateTodo(nametab) {
await globalroutines(null, 'updatefromIndexedDbToStateTodo', nametab, null)
.then(() => {
console.log('updatefromIndexedDbToStateTodo! ')
@@ -340,7 +334,7 @@ sendMessageToSW(recdata, method) {
}
*/
export function setmodifiedIfchanged(recOut, recIn, field) {
function setmodifiedIfchanged(recOut, recIn, field) {
if (String(recOut[field]) !== String(recIn[field])) {
// console.log('*************** CAMPO ', field, 'MODIFICATO!', recOut[field], recIn[field])
recOut.modified = true
@@ -407,8 +401,3 @@ export function table_DeleteRecord(nametable, myobjtrov, id) {
Sync_DeleteItem(nametable, myobjtrov, id)
}
export function isLoggedToSystem() {
const tok = tools.getItemLS(tools.localStorage.token)
return !!tok
}

View File

@@ -122,7 +122,6 @@ namespace Getters {
})
if (UserStore.state.isAdmin) {
state.menulinks = {
Dashboard: {
@@ -175,6 +174,8 @@ namespace Getters {
}
}
console.log('___ return getMenu ', state.menulinks)
return state.menulinks
}, 'getmenu')
@@ -284,7 +285,7 @@ namespace Mutations {
console.log('config', config)
if (config) {
config.value = String(showtype)
Todos.state.showtype = parseInt(config.value)
Todos.state.showtype = parseInt(config.value, 10)
} else {
Todos.state.showtype = showtype
}

View File

@@ -103,10 +103,10 @@ function getLastFirstElemPriority(cat: string, priority: number, atfirst: boolea
if (trovato) {
return myarr.length - 1
} else {
if (priority === tools.Todos.PRIORITY_LOW) {
if (priority === tools.Priority.PRIORITY_LOW) {
return myarr.length - 1
}
else if (priority === tools.Todos.PRIORITY_HIGH) {
else if (priority === tools.Priority.PRIORITY_HIGH) {
return 0
}
}
@@ -150,7 +150,7 @@ function initcat() {
_id: objectId(),
userId: UserStore.state.userId,
descr: '',
priority: tools.Todos.PRIORITY_NORMAL,
priority: tools.Priority.PRIORITY_NORMAL,
completed: false,
created_at: new Date(),
modify_at: new Date(),

View File

@@ -36,7 +36,7 @@ export const tools = {
lang: 'lg'
},
Todos: {
Priority: {
PRIORITY_HIGH: 2,
PRIORITY_NORMAL: 1,
PRIORITY_LOW: 0
@@ -442,10 +442,27 @@ export const tools = {
})
},
dragula_option($service, dragname) {
$service.options(dragname,
{
moves(el, source, handle, sibling) {
return !el.classList.contains('donotdrag') // elements are always draggable by default
},
accepts(el, target, source, sibling) {
return true // elements can be dropped in any of the `containers` by default
},
invalid(el, handle) {
return el.classList.contains('donotdrag') // don't prevent any drags from initiating by default
},
direction: 'vertical'
})
},
isLoggedToSystem() {
const tok = tools.getItemLS(tools.localStorage.token)
return !!tok
}
// _.cloneDeep( Per clonare un oggetto
}

View File

@@ -65,7 +65,6 @@ export default class ProjList extends Vue {
public todotop: string = ''
public todobottom: string = ''
public drag: boolean = true
public startpos: number = 0
public listPriorityLabel: number[] = []
public arrPrior: number[] = []
public itemDragStart: any = null

View File

@@ -56,9 +56,9 @@
<div style="display: none">{{ prior = 0, priorcomplet = false }}</div>
<div>
<!--<q-infinite-scroll :handler="loadMoreTodo" :offset="7">-->
<div class="container" v-dragula="todos_dacompletare(categoryAtt)" drake="second">
<div class="container" v-dragula="proj_dacompletare(categoryAtt)" drake="second">
<div :id="getmyid(mytodo._id)" :index="index"
v-for="(mytodo, index) in todos_dacompletare(categoryAtt)"
v-for="(mytodo, index) in proj_dacompletare(categoryAtt)"
:key="mytodo._id" class="myitemdrag">
<div v-if="(prior !== mytodo.priority) && !mytodo.completed"

View File

@@ -10,14 +10,12 @@ import * as ApiTables from '../../store/Modules/ApiTables'
import { GlobalStore, Todos } from '@store'
import { UserStore } from '@store'
// _.cloneDeep( Per clonare un oggetto
import { costanti } from '../../store/Modules/costanti'
import { Getter, Mutation, State } from 'vuex-class'
const namespace: string = 'Todos'
import globalroutines from '../../globalroutines/index'
const namespace: string = 'Todos'
@Component({
components: { SingleTodo },
@@ -30,6 +28,7 @@ import globalroutines from '../../globalroutines/index'
}
})
export default class Todo extends Vue {
public dragname: string = 'first'
get showtype() {
return Todos.state.showtype
@@ -67,15 +66,6 @@ export default class Todo extends Vue {
}
// get mytodos_dacompletare() {
// return todos_dacompletare(this.categoryAtt)
// }
// @Watch('$route', { immediate: true, deep: true })
// onUrlChange(newVal: any) {
// // Some action
// }
// Computed:
get reload_fromServer() {
return Todos.state.reload_fromServer
@@ -90,7 +80,6 @@ export default class Todo extends Vue {
public todotop: string = ''
public todobottom: string = ''
public drag: boolean = true
public startpos: number = 0
public listPriorityLabel: number[] = []
public arrPrior: number[] = []
public itemDragStart: any = null
@@ -102,7 +91,6 @@ export default class Todo extends Vue {
public scrollable = true
public tmpstrTodos: string = ''
public categoryAtt: string = ''
// public showtype: number = Todos.state.showtype
public $refs: {
single: SingleTodo[]
@@ -118,18 +106,6 @@ export default class Todo extends Vue {
this.categoryAtt = this.$route.params.category
}
// clickaggshowtype () {
// console.log('1B) clickaggshowtype Todos.state.showtype=', Todos.state.showtype)
// Todos.state.showtype = costanti.ShowTypeTask.SHOW_ALL
// console.log('2B) Dopo: showtype=', this.showtype)
// }
public loadval(e) {
console.log('1) loadval, showtype=', this.showtype)
this.showtype = Todos.state.showtype
console.log('2) Dopo: showtype=', this.showtype)
}
public getmyid(id) {
return 'row' + id
}
@@ -140,7 +116,6 @@ export default class Todo extends Vue {
public onStart() {
this.startpos = 0
this.itemDragStart = null
}
@@ -155,13 +130,13 @@ export default class Todo extends Vue {
public getTitlePriority(priority) {
let cl = ''
if (priority === tools.Todos.PRIORITY_HIGH) {
if (priority === tools.Priority.PRIORITY_HIGH) {
cl = 'high_priority'
}
else if (priority === tools.Todos.PRIORITY_NORMAL) {
else if (priority === tools.Priority.PRIORITY_NORMAL) {
cl = 'medium_priority'
}
else if (priority === tools.Todos.PRIORITY_LOW) {
else if (priority === tools.Priority.PRIORITY_LOW) {
cl = 'low_priority'
}
@@ -188,25 +163,8 @@ export default class Todo extends Vue {
public created() {
const $service = this.$dragula.$service
$service.options('first',
{
// isContainer: function (el) {
// return el.classList.contains('dragula-container')
// },
moves(el, source, handle, sibling) {
// console.log('moves')
return !el.classList.contains('donotdrag') // elements are always draggable by default
},
accepts(el, target, source, sibling) {
console.log('accepts dragging '+ el.id + ' from ' + source.id + ' to ' + target.id)
return true // elements can be dropped in any of the `containers` by default
},
invalid(el, handle) {
// console.log('invalid')
return el.classList.contains('donotdrag') // don't prevent any drags from initiating by default
},
direction: 'vertical'
})
tools.dragula_option($service, this.dragname)
$service.eventBus.$on('dragend', (args) => {
const itemdragend: IDrag = {
@@ -264,8 +222,8 @@ export default class Todo extends Vue {
// Set last category selected
localStorage.setItem(tools.localStorage.categorySel, this.categoryAtt)
for (const todosKey in ApiTables.Priority) {
this.listPriorityLabel.push(ApiTables.Priority[todosKey])
for (const todosKey in tools.Priority) {
this.listPriorityLabel.push(tools.Priority[todosKey])
}
// console.log('Priority:' + this.listPriorityLabel)
this.setarrPriority()
@@ -348,7 +306,6 @@ export default class Todo extends Vue {
return Todos.actions.insertTodo({ myobj, atfirst })
}
public async updateitem({ myitem, field }) {
console.log('calling MODIFY updateitem', myitem, field)
// Update the others components...
@@ -426,17 +383,4 @@ export default class Todo extends Vue {
return parseInt(el.attributes.index.value, 10)
}
// setArrTodos() {
//
// let mystr = ''
// let mythis = this
//
// mythis.tmpstrTodos = ''
// return globalroutines(null, 'write', 'todos', this.todos_arr[0])
// .then(function (alldata) {
// mythis.getArrTodos()
// })
// }
//
}

View File

@@ -63,7 +63,7 @@
<div style="display: none">{{ prior = 0, priorcomplet = false }}</div>
<div>
<!--<q-infinite-scroll :handler="loadMoreTodo" :offset="7">-->
<div class="container" v-dragula="todos_dacompletare(categoryAtt)" drake="first">
<div class="container" v-dragula="todos_dacompletare(categoryAtt)" :drake="dragname">
<div :id="getmyid(mytodo._id)" :index="index"
v-for="(mytodo, index) in todos_dacompletare(categoryAtt)"
:key="mytodo._id" class="myitemdrag">