- added fields: longdescr, hoursworked, hoursplanned
This commit is contained in:
@@ -98,7 +98,7 @@ async function dbDeleteItem(call, item) {
|
||||
async function Sync_Execute(cmd, tablesync, nametab, method, item: ITodo, id, msg: String) {
|
||||
// Send to Server to Sync
|
||||
|
||||
console.log('Sync_Execute', cmd, tablesync, nametab, method, item.descr, id, msg)
|
||||
// console.log('Sync_Execute', cmd, tablesync, nametab, method, item.descr, id, msg)
|
||||
|
||||
let cmdSw = cmd
|
||||
if ((cmd === DB.CMD_SYNC_NEW) || (cmd === DB.CMD_DELETE)) {
|
||||
@@ -108,7 +108,7 @@ async function Sync_Execute(cmd, tablesync, nametab, method, item: ITodo, id, ms
|
||||
if ('serviceWorker' in navigator) {
|
||||
return await navigator.serviceWorker.ready
|
||||
.then((sw) => {
|
||||
console.log('---------------------- navigator.serviceWorker.ready')
|
||||
// console.log('---------------------- navigator.serviceWorker.ready')
|
||||
|
||||
return globalroutines(null, 'write', tablesync, item, id)
|
||||
.then((id) => {
|
||||
@@ -120,7 +120,7 @@ async function Sync_Execute(cmd, tablesync, nametab, method, item: ITodo, id, ms
|
||||
_id: multiparams,
|
||||
value: multiparams
|
||||
}
|
||||
console.log('*** swmsg')
|
||||
// console.log('*** swmsg')
|
||||
return globalroutines(null, 'write', 'swmsg', mymsgkey, multiparams)
|
||||
.then((ris) => {
|
||||
// if ('SyncManager' in window) {
|
||||
@@ -288,7 +288,8 @@ async function sendSwMsgIfAvailable() {
|
||||
}
|
||||
|
||||
async function waitAndRefreshData() {
|
||||
return await Projects.actions.dbLoad({ checkPending: false })
|
||||
// #Todo++ Check if is OK
|
||||
await Projects.actions.dbLoad({ checkPending: false, onlyiffirsttime: false })
|
||||
return await Todos.actions.dbLoad({ checkPending: false })
|
||||
}
|
||||
|
||||
@@ -357,7 +358,7 @@ sendMessageToSW(recdata, method) {
|
||||
|
||||
function setmodifiedIfchanged(recOut, recIn, field) {
|
||||
if (String(recOut[field]) !== String(recIn[field])) {
|
||||
// console.log('*************** CAMPO ', field, 'MODIFICATO!', recOut[field], recIn[field])
|
||||
console.log('*************** CAMPO ', field, 'MODIFICATO!', recOut[field], recIn[field])
|
||||
recOut.modified = true
|
||||
recOut[field] = recIn[field]
|
||||
return true
|
||||
@@ -366,14 +367,25 @@ function setmodifiedIfchanged(recOut, recIn, field) {
|
||||
}
|
||||
|
||||
export async function table_ModifyRecord(nametable, myitem, fieldtochange) {
|
||||
|
||||
if (myitem === null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
|
||||
console.log('--> table_ModifyRecord', nametable, myitem.descr)
|
||||
|
||||
const myobjsaved = tools.jsonCopy(myitem)
|
||||
|
||||
/*
|
||||
const mymodule = tools.getModulesByTable(nametable)
|
||||
let param2 = ''
|
||||
if (nametable === 'todos') {
|
||||
param2 = myitem.category
|
||||
}
|
||||
const miorec = mymodule.getters.getRecordById(myobjsaved._id, param2)
|
||||
*/
|
||||
|
||||
// get record from IndexedDb
|
||||
const miorec = await globalroutines(null, 'read', nametable, null, myobjsaved._id)
|
||||
if (miorec === undefined) {
|
||||
@@ -381,6 +393,8 @@ export async function table_ModifyRecord(nametable, myitem, fieldtochange) {
|
||||
return
|
||||
}
|
||||
|
||||
console.log('miorec', miorec.descr, miorec.id_prev)
|
||||
|
||||
if (nametable === 'todos') {
|
||||
if (setmodifiedIfchanged(miorec, myobjsaved, 'completed')) {
|
||||
miorec.completed_at = new Date().getDate()
|
||||
@@ -392,7 +406,7 @@ export async function table_ModifyRecord(nametable, myitem, fieldtochange) {
|
||||
})
|
||||
|
||||
if (miorec.modified) {
|
||||
console.log(nametable + ' MODIFICATO! ', miorec.descr, miorec.pos, 'SALVALO SULLA IndexedDB')
|
||||
console.log(' ' + nametable + ' MODIFICATO! ', miorec.descr, miorec.pos, 'SALVALO SULLA IndexedDB')
|
||||
miorec.modify_at = new Date().getDate()
|
||||
miorec.modified = false
|
||||
|
||||
@@ -407,6 +421,8 @@ export async function table_ModifyRecord(nametable, myitem, fieldtochange) {
|
||||
Sync_SaveItem(nametable, 'PATCH', miorec)
|
||||
|
||||
})
|
||||
} else {
|
||||
console.log(' ', miorec.descr, 'NON MODIF!')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace Getters {
|
||||
route: '/todo', faIcon: 'fa fa-list-alt', materialIcon: 'format_list_numbered', name: 'pages.Todo',
|
||||
routes2: listatodo
|
||||
},
|
||||
{ route: '/projects', faIcon: 'fa fa-list-alt', materialIcon: 'next_week', name: 'pages.Projects' },
|
||||
{ route: '/projects/' + tools.FIRST_PROJ, faIcon: 'fa fa-list-alt', materialIcon: 'next_week', name: 'pages.Projects' },
|
||||
|
||||
{ route: '/category', faIcon: 'fa fa-list-alt', materialIcon: 'category', name: 'pages.Category' },
|
||||
{ route: '/admin/cfgserv', faIcon: 'fa fa-database', materialIcon: 'event_seat', name: 'pages.Admin' },
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IProject, IProjectsState, IParamTodo, IDrag } from 'model'
|
||||
import { IProject, IProjectsState, IDrag } from 'model'
|
||||
import { storeBuilder } from './Store/Store'
|
||||
|
||||
import Api from '@api'
|
||||
@@ -20,7 +20,7 @@ const state: IProjectsState = {
|
||||
visuLastCompleted: 10
|
||||
}
|
||||
|
||||
const fieldtochange: string [] = ['descr', 'completed', 'category', 'expiring_at', 'priority', 'id_prev', 'pos', 'enableExpiring', 'progress']
|
||||
const fieldtochange: string [] = ['descr', 'longdescr', 'hoursplanned', 'hoursworked', 'id_parent', 'completed', 'category', 'expiring_at', 'priority', 'id_prev', 'pos', 'enableExpiring', 'progress']
|
||||
|
||||
const b = storeBuilder.module<IProjectsState>('Projects', state)
|
||||
const stateGetter = b.state()
|
||||
@@ -39,81 +39,94 @@ function getarrByCategory(category: string) {
|
||||
|
||||
function initcat() {
|
||||
|
||||
const tomorrow = new Date()
|
||||
tomorrow.setDate(tomorrow.getDate() + 1)
|
||||
|
||||
const objproj: IProject = {
|
||||
// _id: new Date().toISOString(), // Create NEW
|
||||
_id: objectId(),
|
||||
userId: UserStore.state.userId,
|
||||
descr: '',
|
||||
priority: tools.Priority.PRIORITY_NORMAL,
|
||||
completed: false,
|
||||
created_at: new Date(),
|
||||
modify_at: new Date(),
|
||||
completed_at: new Date(),
|
||||
category: '',
|
||||
expiring_at: tomorrow,
|
||||
enableExpiring: false,
|
||||
id_prev: '',
|
||||
pos: 0,
|
||||
modified: false,
|
||||
progressCalc: 0
|
||||
}
|
||||
// return this.copy(objproj)
|
||||
return objproj
|
||||
let rec = Getters.getters.getRecordEmpty()
|
||||
rec.userId = UserStore.state.userId
|
||||
|
||||
return rec
|
||||
|
||||
}
|
||||
|
||||
namespace Getters {
|
||||
const items_dacompletare = b.read((state: IProjectsState) => (cat: string): IProject[] => {
|
||||
const getRecordEmpty = b.read((state: IProjectsState) => (): IProject => {
|
||||
// const tomorrow = new Date()
|
||||
// tomorrow.setDate(tomorrow.getDate() + 1)
|
||||
|
||||
const obj: IProject = {
|
||||
_id: objectId(),
|
||||
descr: '',
|
||||
id_parent: '',
|
||||
priority: tools.Priority.PRIORITY_NORMAL,
|
||||
completed: false,
|
||||
created_at: new Date(),
|
||||
modify_at: new Date(),
|
||||
completed_at: new Date(),
|
||||
category: '',
|
||||
// expiring_at: tomorrow,
|
||||
enableExpiring: false,
|
||||
id_prev: '',
|
||||
pos: 0,
|
||||
modified: false,
|
||||
progressCalc: 0
|
||||
}
|
||||
|
||||
return obj
|
||||
}, 'getRecordEmpty')
|
||||
|
||||
const items_dacompletare = b.read((state: IProjectsState) => (id_parent: string): IProject[] => {
|
||||
if (state.projects) {
|
||||
return state.projects.filter((proj) => !proj.completed)
|
||||
return tools.mapSort(state.projects.filter((proj) => proj.id_parent === id_parent))
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}, 'items_dacompletare')
|
||||
|
||||
const projs_completati = b.read((state: IProjectsState) => (cat: string): IProject[] => {
|
||||
const getDescrById = b.read((state: IProjectsState) => (id: string): string => {
|
||||
if (id === tools.FIRST_PROJ)
|
||||
return 'Projects'
|
||||
if (state.projects) {
|
||||
if (state.showtype === costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED) {
|
||||
return state.projects.filter((proj) => proj.completed).slice(0, state.visuLastCompleted)
|
||||
} // Show only the first N completed
|
||||
else if (state.showtype === costanti.ShowTypeTask.SHOW_ALL) {
|
||||
return state.projects.filter((proj) => proj.completed)
|
||||
}
|
||||
else {
|
||||
return []
|
||||
}
|
||||
} else {
|
||||
return []
|
||||
const item = state.projects.find((item) => item._id === id)
|
||||
if (!!item)
|
||||
return item.descr
|
||||
}
|
||||
}, 'projs_completati')
|
||||
|
||||
const doneProjectsCount = b.read((state: IProjectsState) => (cat: string): number => {
|
||||
return getters.projs_completati(cat).length
|
||||
}, 'doneProjectsCount')
|
||||
const ProjectsCount = b.read((state: IProjectsState) => (cat: string): number => {
|
||||
return ''
|
||||
}, 'getDescrById')
|
||||
|
||||
const getParentById = b.read((state: IProjectsState) => (id: string): string => {
|
||||
if (state.projects) {
|
||||
return state.projects.length
|
||||
} else {
|
||||
return 0
|
||||
const item = state.projects.find((item) => item._id === id)
|
||||
if (!!item)
|
||||
return item.id_parent
|
||||
}
|
||||
}, 'ProjectsCount')
|
||||
|
||||
return ''
|
||||
}, 'getParentById')
|
||||
|
||||
const getRecordById = b.read((state: IProjectsState) => (id: string): IProject => {
|
||||
if (state.projects) {
|
||||
return state.projects.find((item) => item._id === id)
|
||||
}
|
||||
return null
|
||||
}, 'getRecordById')
|
||||
|
||||
export const getters = {
|
||||
get getRecordEmpty() {
|
||||
return getRecordEmpty()
|
||||
},
|
||||
get items_dacompletare() {
|
||||
return items_dacompletare()
|
||||
},
|
||||
get projs_completati() {
|
||||
return projs_completati()
|
||||
get getDescrById() {
|
||||
return getDescrById()
|
||||
},
|
||||
get doneProjectsCount() {
|
||||
return doneProjectsCount()
|
||||
get getParentById() {
|
||||
return getParentById()
|
||||
},
|
||||
get ProjectsCount() {
|
||||
return ProjectsCount()
|
||||
get getRecordById() {
|
||||
return getRecordById()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,13 +167,21 @@ namespace Mutations {
|
||||
|
||||
namespace Actions {
|
||||
|
||||
async function dbLoad(context, { checkPending }) {
|
||||
console.log('dbLoad', nametable, checkPending, 'userid=', UserStore.state.userId)
|
||||
async function dbLoad(context, { checkPending, onlyiffirsttime }) {
|
||||
|
||||
if (onlyiffirsttime) {
|
||||
if (state.projects.length > 0) {
|
||||
// if already set, then exit.
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if (UserStore.state.userId === '') {
|
||||
return false // Login not made
|
||||
}
|
||||
|
||||
console.log('dbLoad', nametable, checkPending, 'userid=', UserStore.state.userId)
|
||||
|
||||
const ris = await Api.SendReq('/projects/' + UserStore.state.userId, 'GET', null)
|
||||
.then((res) => {
|
||||
if (res.data.projects) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
@@ -190,10 +211,10 @@ namespace Actions {
|
||||
ApiTables.aftercalling(ris, checkPending, 'categories')
|
||||
}
|
||||
|
||||
async function deleteItem(context, { cat, idobj }) {
|
||||
async function deleteItem(context, { idobj }) {
|
||||
console.log('deleteItem: KEY = ', idobj)
|
||||
|
||||
const myarr = getarrByCategory(cat)
|
||||
const myarr = getarrByCategory('')
|
||||
|
||||
const myobjtrov = tools.getElemById(myarr, idobj)
|
||||
|
||||
@@ -218,6 +239,7 @@ namespace Actions {
|
||||
|
||||
objproj.descr = myobj.descr
|
||||
objproj.category = myobj.category
|
||||
objproj.id_parent = myobj.id_parent
|
||||
|
||||
let elemtochange: IProject = null
|
||||
|
||||
@@ -230,7 +252,7 @@ namespace Actions {
|
||||
} else {
|
||||
console.log('INSERT AT THE BOTTOM')
|
||||
// INSERT AT THE BOTTOM , so GET LAST ITEM
|
||||
const lastelem = tools.getLastListNotCompleted(nametable, objproj.category)
|
||||
const lastelem = tools.getLastListNotCompleted(nametable, objproj.id_parent)
|
||||
|
||||
objproj.id_prev = (!!lastelem) ? lastelem._id : ApiTables.LIST_START
|
||||
}
|
||||
@@ -254,50 +276,6 @@ namespace Actions {
|
||||
|
||||
// 3) send to the Server
|
||||
return await ApiTables.Sync_SaveItem(nametable, 'POST', objproj)
|
||||
.then((ris) => {
|
||||
// *** Check if need to be moved because of the --- Priority Ordering --- ...
|
||||
|
||||
const indelem = tools.getIndexById(myarr, objproj._id)
|
||||
let itemdragend
|
||||
if (atfirst) {
|
||||
// Check the second item, if it's different priority, then move to the first position of the priority
|
||||
const secondindelem = indelem + 1
|
||||
if (tools.isOkIndex(myarr, secondindelem)) {
|
||||
const secondelem = tools.getElemByIndex(myarr, secondindelem)
|
||||
if (secondelem.priority !== objproj.priority) {
|
||||
itemdragend = {
|
||||
field: 'priority',
|
||||
idelemtochange: objproj._id,
|
||||
prioritychosen: objproj.priority,
|
||||
category: objproj.category,
|
||||
atfirst
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// get previous of the last
|
||||
const prevlastindelem = indelem - 1
|
||||
if (tools.isOkIndex(myarr, prevlastindelem)) {
|
||||
const prevlastelem = tools.getElemByIndex(myarr, prevlastindelem)
|
||||
if (prevlastelem.priority !== objproj.priority) {
|
||||
itemdragend = {
|
||||
field: 'priority',
|
||||
idelemtochange: objproj._id,
|
||||
prioritychosen: objproj.priority,
|
||||
category: objproj.category,
|
||||
atfirst
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (itemdragend) {
|
||||
swapElems(context, itemdragend)
|
||||
}
|
||||
return ris
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async function modify(context, { myitem, field }) {
|
||||
@@ -307,8 +285,7 @@ namespace Actions {
|
||||
async function swapElems(context, itemdragend: IDrag) {
|
||||
console.log('PROJECT swapElems', itemdragend, state.projects)
|
||||
|
||||
const cat = itemdragend.category
|
||||
const myarr = state.projects
|
||||
const myarr = Getters.getters.items_dacompletare(itemdragend.id_proj)
|
||||
|
||||
tools.swapGeneralElem(nametable, myarr, itemdragend, fieldtochange)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ITodo, ITodosState, IParamTodo, IDrag } from 'model'
|
||||
import { ITodo, ITodosState, IParamTodo, IDrag, IProjectsState, IProject } from 'model'
|
||||
import { storeBuilder } from './Store/Store'
|
||||
|
||||
import Api from '@api'
|
||||
@@ -111,6 +111,14 @@ namespace Getters {
|
||||
}
|
||||
}, 'TodosCount')
|
||||
|
||||
const getRecordById = b.read((state: ITodosState) => (id: string, cat: string): ITodo => {
|
||||
const indcat = getindexbycategory(cat)
|
||||
if (state.todos) {
|
||||
return state.todos[indcat].find((item) => item._id === id)
|
||||
}
|
||||
return null
|
||||
}, 'getRecordById')
|
||||
|
||||
export const getters = {
|
||||
get items_dacompletare() {
|
||||
return items_dacompletare()
|
||||
@@ -123,6 +131,9 @@ namespace Getters {
|
||||
},
|
||||
get TodosCount() {
|
||||
return TodosCount()
|
||||
},
|
||||
get getRecordById() {
|
||||
return getRecordById()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import router from '@router'
|
||||
|
||||
import { serv_constants } from '../Modules/serv_constants'
|
||||
import { tools } from '../Modules/tools'
|
||||
import { GlobalStore, UserStore, Todos } from '@store'
|
||||
import { GlobalStore, UserStore, Todos, Projects } from '@store'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
|
||||
import translate from './../../globalroutines/util'
|
||||
@@ -503,6 +503,7 @@ namespace Actions {
|
||||
await GlobalStore.actions.loadAfterLogin()
|
||||
.then(() => {
|
||||
Todos.actions.dbLoad({ checkPending: true })
|
||||
Projects.actions.dbLoad({ checkPending: true, onlyiffirsttime: true })
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Todos, Projects, UserStore } from '@store'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
import { costanti } from './costanti'
|
||||
import Quasar from 'quasar'
|
||||
import { ITodo } from '@src/model'
|
||||
import { IProject, ITodo } from '@src/model'
|
||||
import * as ApiTables from '@src/store/Modules/ApiTables'
|
||||
|
||||
export interface INotify {
|
||||
@@ -21,7 +21,7 @@ export const tools = {
|
||||
DUPLICATE_EMAIL_ID: 11000,
|
||||
DUPLICATE_USERNAME_ID: 11100,
|
||||
|
||||
FIRST_PROJ: '__FIRSTPROJ',
|
||||
FIRST_PROJ: '__PROJECTS',
|
||||
|
||||
arrLangUsed: ['enUs', 'it', 'es'],
|
||||
|
||||
@@ -52,7 +52,8 @@ export const tools = {
|
||||
COMPLETED: 110,
|
||||
PROGRESS_BAR: 120,
|
||||
PRIORITY: 130,
|
||||
SHOW_TASK: 150
|
||||
SHOW_TASK: 150,
|
||||
EDIT: 160
|
||||
},
|
||||
|
||||
selectPriority: {
|
||||
@@ -253,6 +254,12 @@ export const tools = {
|
||||
|
||||
menuPopupProj: {
|
||||
it: [
|
||||
{
|
||||
id: 10,
|
||||
label: 'Modifica',
|
||||
value: 160, // EDIT
|
||||
icon: 'create'
|
||||
},
|
||||
{
|
||||
id: 40,
|
||||
label: 'Imposta Scadenza',
|
||||
@@ -269,6 +276,12 @@ export const tools = {
|
||||
}
|
||||
],
|
||||
es: [
|
||||
{
|
||||
id: 10,
|
||||
label: 'Editar',
|
||||
value: 160, // EDIT
|
||||
icon: 'create'
|
||||
},
|
||||
{
|
||||
id: 40,
|
||||
label: 'Establecer expiración',
|
||||
@@ -285,6 +298,12 @@ export const tools = {
|
||||
}
|
||||
],
|
||||
enUs: [
|
||||
{
|
||||
id: 10,
|
||||
label: 'Edit',
|
||||
value: 160, // EDIT
|
||||
icon: 'create'
|
||||
},
|
||||
{
|
||||
id: 40,
|
||||
label: 'Set Expiring',
|
||||
@@ -463,6 +482,23 @@ export const tools = {
|
||||
console.log(mystr, 'elem [', elem._id, '] ', elem.descr, ' Pr(', tools.getPriorityByInd(elem.priority), ') [', elem.id_prev, '] modif=', elem.modified)
|
||||
},
|
||||
|
||||
getelemprojstr(elem) {
|
||||
return 'elem [id= ' + elem._id + '] ' + elem.descr + ' [id_prev= ' + elem.id_prev + '] '
|
||||
},
|
||||
|
||||
logga_arrproj(myarr: IProject[]) {
|
||||
let mystr = '\n'
|
||||
myarr.forEach((item) => {
|
||||
mystr += tools.getelemprojstr(item) + ' '
|
||||
})
|
||||
|
||||
return mystr
|
||||
},
|
||||
|
||||
logelemprj(mystr, elem) {
|
||||
console.log(mystr, tools.getelemprojstr(elem))
|
||||
},
|
||||
|
||||
getstrelem(elem) {
|
||||
return 'elem [' + elem._id + '] ' + elem.descr + ' Pr(' + tools.getPriorityByInd(elem.priority) + ') [ID_PREV=' + elem.id_prev + '] modif=' + elem.modified + ' '
|
||||
},
|
||||
@@ -512,13 +548,15 @@ export const tools = {
|
||||
},
|
||||
|
||||
update_idprev(myarr, indelemchange, indelemId) {
|
||||
if (indelemchange >= 0 && indelemchange < myarr.length) {
|
||||
if (tools.isOkIndex(myarr, indelemchange)) {
|
||||
const id_prev = (indelemId >= 0) ? myarr[indelemId]._id : ApiTables.LIST_START
|
||||
console.log('update_idprev [', indelemchange, ']', '[id_prev=', id_prev, ']')
|
||||
if (myarr[indelemchange].id_prev !== id_prev) {
|
||||
myarr[indelemchange].id_prev = id_prev
|
||||
tools.notifyarraychanged(myarr[indelemchange])
|
||||
// tools.notifyarraychanged(myarr)
|
||||
// myarr[indelemchange].modified = true
|
||||
console.log('Index=', indelemchange, 'indtoget', indelemId, tools.getstrelem(myarr[indelemchange]))
|
||||
// console.log('update_idprev Index=', indelemchange, 'indtoget', indelemId, tools.getstrelem(myarr[indelemchange]))
|
||||
console.log(' MODIFICATO! ', myarr[indelemchange].descr , ' PRIMA:', myarr[indelemchange].id_prev, 'DOPO: ', id_prev)
|
||||
myarr[indelemchange].id_prev = id_prev
|
||||
return myarr[indelemchange]
|
||||
}
|
||||
}
|
||||
@@ -536,54 +574,71 @@ export const tools = {
|
||||
console.log('swapElems PRIORITY', itemdragend)
|
||||
}
|
||||
|
||||
if (itemdragend.newIndex === itemdragend.oldIndex)
|
||||
console.log('swapGeneralElem', 'new =', itemdragend.newIndex, 'Old =', itemdragend.oldIndex, itemdragend)
|
||||
|
||||
if (itemdragend.newIndex === itemdragend.oldIndex) {
|
||||
return
|
||||
}
|
||||
|
||||
if (tools.isOkIndex(myarr, itemdragend.newIndex) && tools.isOkIndex(myarr, itemdragend.oldIndex)) {
|
||||
|
||||
console.log('SPLICE!')
|
||||
console.log(' PRIMA!', tools.logga_arrproj(myarr))
|
||||
myarr.splice(itemdragend.newIndex, 0, myarr.splice(itemdragend.oldIndex, 1)[0])
|
||||
tools.notifyarraychanged(myarr[itemdragend.newIndex])
|
||||
tools.notifyarraychanged(myarr[itemdragend.oldIndex])
|
||||
console.log(' DOPO!', tools.logga_arrproj(myarr))
|
||||
|
||||
if (itemdragend.field !== 'priority') {
|
||||
const precind = itemdragend.newIndex - 1
|
||||
const nextind = itemdragend.newIndex + 1
|
||||
// Ora inverti gli indici
|
||||
const indold = itemdragend.oldIndex
|
||||
itemdragend.oldIndex = itemdragend.newIndex
|
||||
itemdragend.newIndex = indold
|
||||
|
||||
if (tools.isOkIndex(myarr, precind) && tools.isOkIndex(myarr, nextind)) {
|
||||
if ((myarr[precind].priority === myarr[nextind].priority) && (myarr[precind].priority !== myarr[itemdragend.newIndex].priority)) {
|
||||
// console.log(' 1)')
|
||||
myarr[itemdragend.newIndex].priority = myarr[precind].priority
|
||||
tools.notifyarraychanged(myarr[itemdragend.newIndex])
|
||||
}
|
||||
} else {
|
||||
if (!tools.isOkIndex(myarr, precind)) {
|
||||
if ((myarr[nextind].priority !== myarr[itemdragend.newIndex].priority)) {
|
||||
// console.log(' 2)')
|
||||
myarr[itemdragend.newIndex].priority = myarr[nextind].priority
|
||||
tools.notifyarraychanged(myarr[itemdragend.newIndex])
|
||||
}
|
||||
if (nametable === 'todos') {
|
||||
if (itemdragend.field !== 'priority') {
|
||||
const precind = itemdragend.newIndex - 1
|
||||
const nextind = itemdragend.newIndex + 1
|
||||
|
||||
} else {
|
||||
if ((myarr[precind].priority !== myarr[itemdragend.newIndex].priority)) {
|
||||
console.log(' 3)')
|
||||
if (tools.isOkIndex(myarr, precind) && tools.isOkIndex(myarr, nextind)) {
|
||||
if ((myarr[precind].priority === myarr[nextind].priority) && (myarr[precind].priority !== myarr[itemdragend.newIndex].priority)) {
|
||||
console.log(' 1)')
|
||||
myarr[itemdragend.newIndex].priority = myarr[precind].priority
|
||||
tools.notifyarraychanged(myarr[itemdragend.newIndex])
|
||||
tools.notifyarraychanged(myarr)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!tools.isOkIndex(myarr, precind)) {
|
||||
if ((myarr[nextind].priority !== myarr[itemdragend.newIndex].priority)) {
|
||||
console.log(' 2)')
|
||||
myarr[itemdragend.newIndex].priority = myarr[nextind].priority
|
||||
tools.notifyarraychanged(myarr)
|
||||
}
|
||||
|
||||
} else {
|
||||
if ((myarr[precind].priority !== myarr[itemdragend.newIndex].priority)) {
|
||||
console.log(' 3)')
|
||||
myarr[itemdragend.newIndex].priority = myarr[precind].priority
|
||||
tools.notifyarraychanged(myarr)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the id_prev property
|
||||
const elem1 = tools.update_idprev(myarr, itemdragend.newIndex, itemdragend.newIndex - 1)
|
||||
const elem2 = tools.update_idprev(myarr, itemdragend.newIndex + 1, itemdragend.newIndex)
|
||||
const elem3 = tools.update_idprev(myarr, itemdragend.oldIndex, itemdragend.oldIndex - 1)
|
||||
const elem4 = tools.update_idprev(myarr, itemdragend.oldIndex + 1, itemdragend.oldIndex)
|
||||
const elem1 = tools.update_idprev(myarr, itemdragend.newIndex, itemdragend.newIndex - 1) // 0, -1
|
||||
const elem2 = tools.update_idprev(myarr, itemdragend.newIndex + 1, itemdragend.newIndex) // 1, 0
|
||||
const elem3 = tools.update_idprev(myarr, itemdragend.oldIndex, itemdragend.oldIndex - 1) // 1, 0
|
||||
const elem4 = tools.update_idprev(myarr, itemdragend.oldIndex + 1, itemdragend.oldIndex) // 2, 1
|
||||
|
||||
await ApiTables.table_ModifyRecord(nametable, elem1, fieldtochange)
|
||||
await ApiTables.table_ModifyRecord(nametable, elem2, fieldtochange)
|
||||
await ApiTables.table_ModifyRecord(nametable, elem3, fieldtochange)
|
||||
await ApiTables.table_ModifyRecord(nametable, elem4, fieldtochange)
|
||||
|
||||
|
||||
tools.notifyarraychanged(myarr)
|
||||
|
||||
console.log('arr FINALE', tools.logga_arrproj(myarr))
|
||||
|
||||
// Update the records:
|
||||
}
|
||||
},
|
||||
@@ -650,7 +705,7 @@ export const tools = {
|
||||
|
||||
getLastListNotCompleted(nametable, cat) {
|
||||
const module = tools.getModulesByTable(nametable)
|
||||
let arr = module.getters.items_dacompletare(cat)
|
||||
const arr = module.getters.items_dacompletare(cat)
|
||||
|
||||
return (arr.length > 0) ? arr[arr.length - 1] : null
|
||||
},
|
||||
@@ -813,6 +868,75 @@ export const tools = {
|
||||
isLoggedToSystem() {
|
||||
const tok = tools.getItemLS(tools.localStorage.token)
|
||||
return !!tok
|
||||
},
|
||||
|
||||
mapSort(linkedList) {
|
||||
const sortedList = []
|
||||
const map = new Map()
|
||||
let currentId = null
|
||||
|
||||
// console.log('linkedList', linkedList)
|
||||
|
||||
// index the linked list by previous_item_id
|
||||
for (let i = 0; i < linkedList.length; i++) {
|
||||
const item = linkedList[i]
|
||||
// tools.logelemprj(i, item)
|
||||
if (item.id_prev === ApiTables.LIST_START) {
|
||||
// first item
|
||||
currentId = String(item._id)
|
||||
// console.log('currentId', currentId);
|
||||
sortedList.push(item)
|
||||
} else {
|
||||
map.set(item.id_prev, i)
|
||||
}
|
||||
}
|
||||
|
||||
let i = 0
|
||||
while (sortedList.length < linkedList.length) {
|
||||
// get the item with a previous item ID referencing the current item
|
||||
const nextItem = linkedList[map.get(currentId)]
|
||||
if (nextItem === undefined) {
|
||||
break
|
||||
}
|
||||
sortedList.push(nextItem)
|
||||
// tools.logelemprj('FATTO:' + i, nextItem)
|
||||
currentId = String(nextItem._id)
|
||||
i++
|
||||
}
|
||||
|
||||
if (sortedList.length < linkedList.length) {
|
||||
console.log('!!!!! NON CI SONO TUTTI !!!!!', sortedList.length, linkedList.length)
|
||||
// Forget something not in a List !
|
||||
for (const itemsorted of sortedList) {
|
||||
if (linkedList.filter((item) => item._id === itemsorted._id)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// console.log('DOPO sortedList', sortedList);
|
||||
|
||||
return sortedList
|
||||
},
|
||||
|
||||
getProgressClassColor(progress) {
|
||||
if (progress > 66) {
|
||||
return 'highperc'
|
||||
} else if (progress > 33) {
|
||||
return 'medperc'
|
||||
} else {
|
||||
return 'lowperc'
|
||||
}
|
||||
},
|
||||
|
||||
getProgressColor(progress) {
|
||||
if (progress > 66) {
|
||||
return 'green'
|
||||
} else if (progress > 33) {
|
||||
return 'blue'
|
||||
} else {
|
||||
return 'red'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user