++ Added "Projects" (step 1)
This commit is contained in:
@@ -17,7 +17,7 @@ export interface IProject {
|
||||
progress?: number
|
||||
}
|
||||
|
||||
export interface IParamProject {
|
||||
export interface IParamIProject {
|
||||
categorySel?: string
|
||||
checkPending?: boolean
|
||||
id?: string
|
||||
@@ -37,13 +37,10 @@ export interface IDrag {
|
||||
}
|
||||
*/
|
||||
|
||||
export interface IProjectState {
|
||||
export interface IProjectsState {
|
||||
showtype: number
|
||||
todos: {}
|
||||
projs: {}
|
||||
categories: string[]
|
||||
// todos_changed: number
|
||||
reload_fromServer: number
|
||||
testpao: string
|
||||
insidePending: boolean
|
||||
visuLastCompleted: number
|
||||
}
|
||||
|
||||
@@ -7,3 +7,4 @@ export * from './key-value'
|
||||
|
||||
export * from './Categories'
|
||||
export * from './Todos'
|
||||
export * from './Projects'
|
||||
|
||||
@@ -142,7 +142,7 @@ export namespace ApiTool {
|
||||
// console.log('----------------------- LEGGO QUALCOSA ')
|
||||
|
||||
const promises = myrecs.map((rec) => {
|
||||
let link = '/todos'
|
||||
let link = '/' + ApiTables.getLinkByTableName(table)
|
||||
|
||||
if (method !== 'POST') {
|
||||
link += '/' + rec._id
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Api from '@api'
|
||||
import { ITodo } from '@src/model'
|
||||
import { GlobalStore, Todos, UserStore } from '@store'
|
||||
import { GlobalStore, Todos, Projects, UserStore } from '@store'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
import { serv_constants } from '@src/store/Modules/serv_constants'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
@@ -268,6 +268,7 @@ async function sendSwMsgIfAvailable() {
|
||||
}
|
||||
|
||||
async function waitAndRefreshData() {
|
||||
return await Projects.actions.dbLoadProjects({ checkPending: false })
|
||||
return await Todos.actions.dbLoadTodo({ checkPending: false })
|
||||
}
|
||||
|
||||
@@ -401,3 +402,11 @@ export function table_DeleteRecord(nametable, myobjtrov, id) {
|
||||
Sync_DeleteItem(nametable, myobjtrov, id)
|
||||
|
||||
}
|
||||
|
||||
export function getLinkByTableName(nametable) {
|
||||
if (nametable === 'todos') {
|
||||
return 'todos'
|
||||
} else if (nametable === 'projects') {
|
||||
return 'projects'
|
||||
}
|
||||
}
|
||||
|
||||
364
src/store/Modules/Projects.ts
Normal file
364
src/store/Modules/Projects.ts
Normal file
@@ -0,0 +1,364 @@
|
||||
import { IProject, IProjectsState, IParamTodo, IDrag } from 'model'
|
||||
import { storeBuilder } from './Store/Store'
|
||||
|
||||
import Api from '@api'
|
||||
import { tools } from './tools'
|
||||
import * as ApiTables from './ApiTables'
|
||||
import { GlobalStore, UserStore } from '@store'
|
||||
import globalroutines from './../../globalroutines/index'
|
||||
import objectId from '@src/js/objectId'
|
||||
import { costanti } from '@src/store/Modules/costanti'
|
||||
|
||||
const nametable = 'projs'
|
||||
|
||||
// import _ from 'lodash'
|
||||
|
||||
const state: IProjectsState = {
|
||||
showtype: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED,
|
||||
projs: {},
|
||||
categories: [],
|
||||
insidePending: false,
|
||||
visuLastCompleted: 10
|
||||
}
|
||||
|
||||
const fieldtochange: string [] = ['descr', 'completed', 'category', 'expiring_at', 'priority', 'id_prev', 'pos', 'enableExpiring', 'progress']
|
||||
|
||||
const b = storeBuilder.module<IProjectsState>('Projects', state)
|
||||
const stateGetter = b.state()
|
||||
|
||||
function getindexbycategory(category: string) {
|
||||
return state.categories.indexOf(category)
|
||||
}
|
||||
|
||||
function gettodosByCategory(category: string) {
|
||||
const indcat = state.categories.indexOf(category)
|
||||
if (!state.projs[indcat]) {
|
||||
return []
|
||||
}
|
||||
return state.projs[indcat]
|
||||
}
|
||||
|
||||
function isValidIndex(cat, index) {
|
||||
const myarr = gettodosByCategory(cat)
|
||||
return (index >= 0 && index < myarr.length)
|
||||
}
|
||||
|
||||
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,
|
||||
progress: 0
|
||||
}
|
||||
// return this.copy(objproj)
|
||||
return objproj
|
||||
|
||||
}
|
||||
|
||||
namespace Getters {
|
||||
const projs_dacompletare = b.read((state: IProjectsState) => (cat: string): IProject[] => {
|
||||
const indcat = getindexbycategory(cat)
|
||||
if (state.projs[indcat]) {
|
||||
return state.projs[indcat].filter((proj) => !proj.completed)
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}, 'projs_dacompletare')
|
||||
|
||||
const projs_completati = b.read((state: IProjectsState) => (cat: string): IProject[] => {
|
||||
const indcat = getindexbycategory(cat)
|
||||
if (state.projs[indcat]) {
|
||||
if (state.showtype === costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED) {
|
||||
return state.projs[indcat].filter((proj) => proj.completed).slice(0, state.visuLastCompleted)
|
||||
} // Show only the first N completed
|
||||
else if (state.showtype === costanti.ShowTypeTask.SHOW_ALL) {
|
||||
return state.projs[indcat].filter((proj) => proj.completed)
|
||||
}
|
||||
else {
|
||||
return []
|
||||
}
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}, '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 => {
|
||||
const indcat = getindexbycategory(cat)
|
||||
if (state.projs[indcat]) {
|
||||
return state.projs[indcat].length
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}, 'ProjectsCount')
|
||||
|
||||
export const getters = {
|
||||
get projs_dacompletare() {
|
||||
return projs_dacompletare()
|
||||
},
|
||||
get projs_completati() {
|
||||
return projs_completati()
|
||||
},
|
||||
get doneProjectsCount() {
|
||||
return doneProjectsCount()
|
||||
},
|
||||
get ProjectsCount() {
|
||||
return ProjectsCount()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace Mutations {
|
||||
|
||||
function findIndTodoById(state: IProjectsState, data: IParamTodo) {
|
||||
const indcat = state.categories.indexOf(data.categorySel)
|
||||
if (indcat >= 0) {
|
||||
return state.projs[indcat].findIndex((elem) => elem._id === data.id)
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
function createNewItem(state: IProjectsState, { objproj, atfirst, categorySel }) {
|
||||
let indcat = state.categories.indexOf(categorySel)
|
||||
if (indcat === -1) {
|
||||
state.categories.push(categorySel)
|
||||
indcat = state.categories.indexOf(categorySel)
|
||||
}
|
||||
console.log('createNewItem', objproj, 'cat=', categorySel, 'state.projs[indcat]', state.projs[indcat])
|
||||
if (state.projs[indcat] === undefined) {
|
||||
state.projs[indcat] = []
|
||||
state.projs[indcat].push(objproj)
|
||||
console.log('push state.projs[indcat]', state.projs)
|
||||
return
|
||||
}
|
||||
if (atfirst) {
|
||||
state.projs[indcat].unshift(objproj)
|
||||
}
|
||||
else {
|
||||
state.projs[indcat].push(objproj)
|
||||
}
|
||||
|
||||
console.log('state.projs[indcat]', state.projs[indcat])
|
||||
|
||||
}
|
||||
|
||||
function deletemyitem(state: IProjectsState, myitem: IProject) {
|
||||
// Find record
|
||||
const indcat = state.categories.indexOf(myitem.category)
|
||||
const ind = findIndTodoById(state, { id: myitem._id, categorySel: myitem.category })
|
||||
|
||||
ApiTables.removeitemfromarray(state.projs[indcat], ind)
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
deletemyitem: b.commit(deletemyitem),
|
||||
createNewItem: b.commit(createNewItem)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Actions {
|
||||
|
||||
async function dbLoadProjects(context, { checkPending }) {
|
||||
console.log('dbLoadProjects', checkPending, 'userid=', UserStore.state.userId)
|
||||
|
||||
if (UserStore.state.userId === '') {
|
||||
return false // Login not made
|
||||
}
|
||||
|
||||
const ris = await Api.SendReq('/projects/' + UserStore.state.userId, 'GET', null)
|
||||
.then((res) => {
|
||||
if (res.data.projs) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
state.projs = res.data.projs
|
||||
state.categories = res.data.categories
|
||||
} else {
|
||||
state.projs = [[]]
|
||||
}
|
||||
|
||||
state.showtype = parseInt(GlobalStore.getters.getConfigStringbyId({
|
||||
id: costanti.CONFIG_ID_SHOW_TYPE_TODOS,
|
||||
default: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED
|
||||
}), 10)
|
||||
|
||||
// console.log('ARRAY TODOS = ', state.projs)
|
||||
if (process.env.DEBUG === '1') {
|
||||
console.log('dbLoadProjects', 'state.projs', state.projs, 'state.categories', state.categories)
|
||||
}
|
||||
|
||||
return res
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error dbLoadProjects', error)
|
||||
UserStore.mutations.setErrorCatch(error)
|
||||
return error
|
||||
})
|
||||
|
||||
ApiTables.aftercalling(ris, checkPending, 'categories')
|
||||
}
|
||||
|
||||
async function deleteItem(context, { cat, idobj }) {
|
||||
console.log('deleteItem: KEY = ', idobj)
|
||||
|
||||
const myarr = gettodosByCategory(cat)
|
||||
|
||||
const myobjtrov = tools.getElemById(myarr, idobj)
|
||||
|
||||
console.log('myobjtrov', myobjtrov.descr)
|
||||
|
||||
if (!!myobjtrov) {
|
||||
const myobjnext = tools.getElemPrevById(myarr, myobjtrov._id)
|
||||
|
||||
if (!!myobjnext) {
|
||||
myobjnext.id_prev = myobjtrov.id_prev
|
||||
myobjnext.modified = true
|
||||
await modify(context, { myitem: myobjnext, field: 'id_prev' })
|
||||
}
|
||||
|
||||
ApiTables.table_DeleteRecord(nametable, myobjtrov, idobj)
|
||||
}
|
||||
}
|
||||
|
||||
async function insertProject(context, { myobj, atfirst }) {
|
||||
|
||||
const objproj = initcat()
|
||||
|
||||
objproj.descr = myobj.descr
|
||||
objproj.category = myobj.category
|
||||
|
||||
let elemtochange: IProject = null
|
||||
|
||||
const myarr = gettodosByCategory(objproj.category)
|
||||
|
||||
if (atfirst) {
|
||||
console.log('INSERT AT THE TOP')
|
||||
elemtochange = tools.getFirstList(myarr)
|
||||
objproj.id_prev = ApiTables.LIST_START
|
||||
} else {
|
||||
console.log('INSERT AT THE BOTTOM')
|
||||
// INSERT AT THE BOTTOM , so GET LAST ITEM
|
||||
const lastelem = tools.getLastListNotCompleted(nametable, objproj.category)
|
||||
|
||||
objproj.id_prev = (!!lastelem) ? lastelem._id : ApiTables.LIST_START
|
||||
}
|
||||
objproj.modified = false
|
||||
|
||||
Mutations.mutations.createNewItem({ objproj, atfirst, categorySel: objproj.category }) // 1) Create record in Memory
|
||||
|
||||
const id = await globalroutines(context, 'write', nametable, objproj) // 2) Insert into the IndexedDb
|
||||
|
||||
let field = ''
|
||||
if (atfirst) { // update also the last elem
|
||||
if (!!elemtochange) {
|
||||
elemtochange.id_prev = id
|
||||
console.log('elemtochange', elemtochange)
|
||||
field = 'id_prev'
|
||||
|
||||
// Modify the other record
|
||||
await modify(context, { myitem: elemtochange, field })
|
||||
}
|
||||
}
|
||||
|
||||
// 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 }) {
|
||||
return await ApiTables.table_ModifyRecord(nametable, myitem, fieldtochange)
|
||||
}
|
||||
|
||||
async function swapElems(context, itemdragend: IDrag) {
|
||||
console.log('swapElems', itemdragend)
|
||||
console.log('state.projs', state.projs)
|
||||
console.log('state.categories', state.categories)
|
||||
|
||||
const cat = itemdragend.category
|
||||
const indcat = state.categories.indexOf(cat)
|
||||
const myarr = state.projs[indcat]
|
||||
|
||||
tools.swapGeneralElem(nametable, myarr, itemdragend, fieldtochange)
|
||||
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
dbLoadProjects: b.dispatch(dbLoadProjects),
|
||||
swapElems: b.dispatch(swapElems),
|
||||
deleteItem: b.dispatch(deleteItem),
|
||||
insertProject: b.dispatch(insertProject),
|
||||
modify: b.dispatch(modify)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Module
|
||||
const ProjectsModule = {
|
||||
get state() {
|
||||
return stateGetter()
|
||||
},
|
||||
getters: Getters.getters,
|
||||
mutations: Mutations.mutations,
|
||||
actions: Actions.actions
|
||||
}
|
||||
|
||||
export default ProjectsModule
|
||||
@@ -44,102 +44,6 @@ function gettodosByCategory(category: string) {
|
||||
return state.todos[indcat]
|
||||
}
|
||||
|
||||
function isValidIndex(cat, index) {
|
||||
const myarr = gettodosByCategory(cat)
|
||||
return (index >= 0 && index < myarr.length)
|
||||
}
|
||||
|
||||
function getElemByIndex(cat, index) {
|
||||
const myarr = gettodosByCategory(cat)
|
||||
|
||||
if (index >= 0 && index < myarr.length) {
|
||||
return myarr[index]
|
||||
}
|
||||
else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function getElemById(cat, id) {
|
||||
const myarr = gettodosByCategory(cat)
|
||||
return myarr.find((elem) => elem._id === id)
|
||||
}
|
||||
|
||||
function getIndexById(cat, id) {
|
||||
const myarr = gettodosByCategory(cat)
|
||||
return myarr.findIndex((elem) => elem._id === id)
|
||||
}
|
||||
|
||||
function getElemPrevById(cat, id) {
|
||||
const myarr = gettodosByCategory(cat)
|
||||
return myarr.find((elem) => elem.id_prev === id)
|
||||
}
|
||||
|
||||
function getLastFirstElemPriority(cat: string, priority: number, atfirst: boolean, escludiId: string) {
|
||||
const myarr = gettodosByCategory(cat)
|
||||
if (myarr === null) {
|
||||
return -1
|
||||
}
|
||||
|
||||
let trovato: boolean = false
|
||||
|
||||
console.log('priority', priority)
|
||||
|
||||
for (let indrec = 0; indrec < myarr.length; indrec++) {
|
||||
if ((myarr[indrec].priority === priority) && (myarr[indrec]._id !== escludiId)) {
|
||||
trovato = true
|
||||
if (atfirst) {
|
||||
return indrec - 1
|
||||
}
|
||||
} else {
|
||||
if (trovato) {
|
||||
return indrec
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('trovato?', trovato, 'indrec')
|
||||
|
||||
if (trovato) {
|
||||
return myarr.length - 1
|
||||
} else {
|
||||
if (priority === tools.Priority.PRIORITY_LOW) {
|
||||
return myarr.length - 1
|
||||
}
|
||||
else if (priority === tools.Priority.PRIORITY_HIGH) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getFirstList(cat) {
|
||||
const myarr = gettodosByCategory(cat)
|
||||
return myarr.find((elem) => elem.id_prev === ApiTables.LIST_START)
|
||||
}
|
||||
|
||||
function getLastListNotCompleted(cat) {
|
||||
const arr = Todos.getters.todos_dacompletare(cat)
|
||||
return (arr.length > 0) ? arr[arr.length - 1] : null
|
||||
}
|
||||
|
||||
function getstrelem(elem) {
|
||||
return 'ID [' + elem._id + '] ' + elem.descr + ' [ID_PREV=' + elem.id_prev + '] modif=' + elem.modified
|
||||
}
|
||||
|
||||
function update_idprev(indcat, indelemchange, indelemId) {
|
||||
if (indelemchange >= 0 && indelemchange < state.todos[indcat].length) {
|
||||
const id_prev = (indelemId >= 0) ? state.todos[indcat][indelemId]._id : ApiTables.LIST_START
|
||||
if (state.todos[indcat][indelemchange].id_prev !== id_prev) {
|
||||
state.todos[indcat][indelemchange].id_prev = id_prev
|
||||
tools.notifyarraychanged(state.todos[indcat][indelemchange])
|
||||
// state.todos[indcat][indelemchange].modified = true
|
||||
console.log('Index=', indelemchange, 'indtoget', indelemId, getstrelem(state.todos[indcat][indelemchange]))
|
||||
return state.todos[indcat][indelemchange]
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
function initcat() {
|
||||
|
||||
const tomorrow = new Date()
|
||||
@@ -313,12 +217,15 @@ namespace Actions {
|
||||
|
||||
async function deleteItem(context, { cat, idobj }) {
|
||||
console.log('deleteItem: KEY = ', idobj)
|
||||
const myobjtrov = getElemById(cat, idobj)
|
||||
|
||||
const myarr = gettodosByCategory(cat)
|
||||
|
||||
const myobjtrov = tools.getElemById(myarr, idobj)
|
||||
|
||||
console.log('myobjtrov', myobjtrov.descr)
|
||||
|
||||
if (!!myobjtrov) {
|
||||
const myobjnext = getElemPrevById(cat, myobjtrov._id)
|
||||
const myobjnext = tools.getElemPrevById(myarr, myobjtrov._id)
|
||||
|
||||
if (!!myobjnext) {
|
||||
myobjnext.id_prev = myobjtrov.id_prev
|
||||
@@ -339,28 +246,24 @@ namespace Actions {
|
||||
|
||||
let elemtochange: ITodo = null
|
||||
|
||||
const myarr = gettodosByCategory(objtodo.category)
|
||||
|
||||
if (atfirst) {
|
||||
console.log('INSERT AT THE TOP')
|
||||
elemtochange = getFirstList(objtodo.category)
|
||||
elemtochange = tools.getFirstList(myarr)
|
||||
objtodo.id_prev = ApiTables.LIST_START
|
||||
} else {
|
||||
console.log('INSERT AT THE BOTTOM')
|
||||
// INSERT AT THE BOTTOM , so GET LAST ITEM
|
||||
const lastelem = getLastListNotCompleted(objtodo.category)
|
||||
|
||||
console.log('lastelem', lastelem)
|
||||
const lastelem = tools.getLastListNotCompleted(nametable, objtodo.category)
|
||||
|
||||
objtodo.id_prev = (!!lastelem) ? lastelem._id : ApiTables.LIST_START
|
||||
}
|
||||
objtodo.modified = false
|
||||
|
||||
// console.log('objtodo', objtodo, 'ID_PREV=', objtodo.id_prev)
|
||||
Todos.mutations.createNewItem({ objtodo, atfirst, categorySel: objtodo.category }) // 1) Create record in Memory
|
||||
|
||||
// 1) Create record in Memory
|
||||
Todos.mutations.createNewItem({ objtodo, atfirst, categorySel: objtodo.category })
|
||||
|
||||
// 2) Insert into the IndexedDb
|
||||
const id = await globalroutines(context, 'write', nametable, objtodo)
|
||||
const id = await globalroutines(context, 'write', nametable, objtodo) // 2) Insert into the IndexedDb
|
||||
|
||||
let field = ''
|
||||
if (atfirst) { // update also the last elem
|
||||
@@ -377,14 +280,15 @@ namespace Actions {
|
||||
// 3) send to the Server
|
||||
return await ApiTables.Sync_SaveItem(nametable, 'POST', objtodo)
|
||||
.then((ris) => {
|
||||
// Check if need to be moved...
|
||||
const indelem = getIndexById(objtodo.category, objtodo._id)
|
||||
// *** Check if need to be moved because of the --- Priority Ordering --- ...
|
||||
|
||||
const indelem = tools.getIndexById(myarr, objtodo._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 (isValidIndex(objtodo.category, secondindelem)) {
|
||||
const secondelem = getElemByIndex(objtodo.category, secondindelem)
|
||||
if (tools.isOkIndex(myarr, secondindelem)) {
|
||||
const secondelem = tools.getElemByIndex(myarr, secondindelem)
|
||||
if (secondelem.priority !== objtodo.priority) {
|
||||
itemdragend = {
|
||||
field: 'priority',
|
||||
@@ -399,8 +303,8 @@ namespace Actions {
|
||||
} else {
|
||||
// get previous of the last
|
||||
const prevlastindelem = indelem - 1
|
||||
if (isValidIndex(objtodo.category, prevlastindelem)) {
|
||||
const prevlastelem = getElemByIndex(objtodo.category, prevlastindelem)
|
||||
if (tools.isOkIndex(myarr, prevlastindelem)) {
|
||||
const prevlastelem = tools.getElemByIndex(myarr, prevlastindelem)
|
||||
if (prevlastelem.priority !== objtodo.priority) {
|
||||
itemdragend = {
|
||||
field: 'priority',
|
||||
@@ -429,67 +333,12 @@ namespace Actions {
|
||||
console.log('swapElems', itemdragend)
|
||||
console.log('state.todos', state.todos)
|
||||
console.log('state.categories', state.categories)
|
||||
|
||||
const cat = itemdragend.category
|
||||
const indcat = state.categories.indexOf(cat)
|
||||
const myarr = state.todos[indcat]
|
||||
|
||||
if (itemdragend.field === 'priority') {
|
||||
// get last elem priority
|
||||
console.log('get last elem priority')
|
||||
itemdragend.newIndex = getLastFirstElemPriority(itemdragend.category, itemdragend.prioritychosen, itemdragend.atfirst, itemdragend.idelemtochange)
|
||||
itemdragend.oldIndex = getIndexById(itemdragend.category, itemdragend.idelemtochange)
|
||||
|
||||
console.log('swapElems PRIORITY', itemdragend)
|
||||
}
|
||||
|
||||
console.log('indcat', indcat)
|
||||
|
||||
if (isValidIndex(cat, indcat) && isValidIndex(cat, itemdragend.newIndex) && isValidIndex(cat, itemdragend.oldIndex)) {
|
||||
console.log('isValidIndex')
|
||||
state.todos[indcat].splice(itemdragend.newIndex, 0, state.todos[indcat].splice(itemdragend.oldIndex, 1)[0])
|
||||
tools.notifyarraychanged(state.todos[indcat][itemdragend.newIndex])
|
||||
tools.notifyarraychanged(state.todos[indcat][itemdragend.oldIndex])
|
||||
|
||||
if (itemdragend.field !== 'priority') {
|
||||
const precind = itemdragend.newIndex - 1
|
||||
const nextind = itemdragend.newIndex + 1
|
||||
|
||||
if (isValidIndex(cat, precind) && isValidIndex(cat, nextind)) {
|
||||
if ((state.todos[indcat][precind].priority === state.todos[indcat][nextind].priority) && (state.todos[indcat][precind].priority !== state.todos[indcat][itemdragend.newIndex].priority)) {
|
||||
console.log(' 1)')
|
||||
state.todos[indcat][itemdragend.newIndex].priority = state.todos[indcat][precind].priority
|
||||
tools.notifyarraychanged(state.todos[indcat][itemdragend.newIndex])
|
||||
}
|
||||
} else {
|
||||
if (!isValidIndex(cat, precind)) {
|
||||
if ((state.todos[indcat][nextind].priority !== state.todos[indcat][itemdragend.newIndex].priority)) {
|
||||
console.log(' 2)')
|
||||
state.todos[indcat][itemdragend.newIndex].priority = state.todos[indcat][nextind].priority
|
||||
tools.notifyarraychanged(state.todos[indcat][itemdragend.newIndex])
|
||||
}
|
||||
|
||||
} else {
|
||||
if ((state.todos[indcat][precind].priority !== state.todos[indcat][itemdragend.newIndex].priority)) {
|
||||
console.log(' 3)')
|
||||
state.todos[indcat][itemdragend.newIndex].priority = state.todos[indcat][precind].priority
|
||||
tools.notifyarraychanged(state.todos[indcat][itemdragend.newIndex])
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Update the id_prev property
|
||||
const elem1 = update_idprev(indcat, itemdragend.newIndex, itemdragend.newIndex - 1)
|
||||
const elem2 = update_idprev(indcat, itemdragend.newIndex + 1, itemdragend.newIndex)
|
||||
const elem3 = update_idprev(indcat, itemdragend.oldIndex, itemdragend.oldIndex - 1)
|
||||
const elem4 = update_idprev(indcat, itemdragend.oldIndex + 1, itemdragend.oldIndex)
|
||||
|
||||
// Update the records:
|
||||
await modify(context, { myitem: elem1, field: 'id_prev' })
|
||||
await modify(context, { myitem: elem2, field: 'id_prev' })
|
||||
await modify(context, { myitem: elem3, field: 'id_prev' })
|
||||
await modify(context, { myitem: elem4, field: 'id_prev' })
|
||||
}
|
||||
tools.swapGeneralElem(nametable, myarr, itemdragend, fieldtochange)
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,3 +2,4 @@ export {storeBuilder} from './Store/Store'
|
||||
export {default as GlobalStore} from './GlobalStore'
|
||||
export {default as UserStore} from './UserStore'
|
||||
export {default as Todos} from './Todos'
|
||||
export {default as Projects} from './Projects'
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { UserStore } from '@store'
|
||||
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 * as ApiTables from '@src/store/Modules/ApiTables'
|
||||
|
||||
export interface INotify {
|
||||
color?: string | 'primary'
|
||||
@@ -346,6 +348,66 @@ export const tools = {
|
||||
]
|
||||
},
|
||||
|
||||
getTitlePriority(priority) {
|
||||
let cl = ''
|
||||
|
||||
if (priority === tools.Priority.PRIORITY_HIGH) {
|
||||
cl = 'high_priority'
|
||||
}
|
||||
else if (priority === tools.Priority.PRIORITY_NORMAL) {
|
||||
cl = 'medium_priority'
|
||||
}
|
||||
else if (priority === tools.Priority.PRIORITY_LOW) {
|
||||
cl = 'low_priority'
|
||||
}
|
||||
|
||||
return cl + ' titlePriority'
|
||||
},
|
||||
|
||||
getPriorityByInd(index) {
|
||||
// console.log('LANG in PRIOR', UserStore.state.lang)
|
||||
try {
|
||||
const arr = tools.selectPriority[UserStore.state.lang]
|
||||
for (const rec of arr) {
|
||||
if (rec.value === index) {
|
||||
return rec.label
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Error: ', e)
|
||||
}
|
||||
return ''
|
||||
},
|
||||
|
||||
logelem(mystr, elem) {
|
||||
console.log(mystr, 'elem [', elem._id, '] ', elem.descr, ' Pr(', tools.getPriorityByInd(elem.priority), ') [', elem.id_prev, '] modif=', elem.modified)
|
||||
},
|
||||
|
||||
getstrelem(elem) {
|
||||
return 'elem [' + elem._id + '] ' + elem.descr + ' Pr(' + tools.getPriorityByInd(elem.priority) + ') [ID_PREV=' + elem.id_prev + '] modif=' + elem.modified + ' '
|
||||
},
|
||||
|
||||
logga_arr(myarr: ITodo[]) {
|
||||
let mystr = '\n'
|
||||
myarr.forEach((item) => {
|
||||
mystr += '[' + item.pos + '] ' + item.descr + ' Pr(' + tools.getPriorityByInd(item.priority) + ') [' + item.id_prev + '] modif=' + item.modified + '\n'
|
||||
// mystr += '[' + item.pos + '] ' + item.descr + '\n'
|
||||
})
|
||||
|
||||
return mystr
|
||||
},
|
||||
|
||||
touchmove(scrollable) {
|
||||
if (window) {
|
||||
window.addEventListener('touchmove', (e) => {
|
||||
// console.log('touchmove')
|
||||
if (!scrollable) {
|
||||
e.preventDefault()
|
||||
}
|
||||
}, { passive: false })
|
||||
}
|
||||
},
|
||||
|
||||
jsonCopy(src) {
|
||||
return JSON.parse(JSON.stringify(src))
|
||||
},
|
||||
@@ -365,6 +427,156 @@ export const tools = {
|
||||
}
|
||||
},
|
||||
|
||||
isOkIndex(myarr, index) {
|
||||
return (index >= 0 && index < myarr.length)
|
||||
},
|
||||
|
||||
update_idprev(myarr, indelemchange, indelemId) {
|
||||
if (indelemchange >= 0 && indelemchange < myarr.length) {
|
||||
const id_prev = (indelemId >= 0) ? myarr[indelemId]._id : ApiTables.LIST_START
|
||||
if (myarr[indelemchange].id_prev !== id_prev) {
|
||||
myarr[indelemchange].id_prev = id_prev
|
||||
tools.notifyarraychanged(myarr[indelemchange])
|
||||
// myarr[indelemchange].modified = true
|
||||
console.log('Index=', indelemchange, 'indtoget', indelemId, tools.getstrelem(myarr[indelemchange]))
|
||||
return myarr[indelemchange]
|
||||
}
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
async swapGeneralElem(nametable, myarr, itemdragend, fieldtochange) {
|
||||
|
||||
if (itemdragend.field === 'priority') {
|
||||
// get last elem priority
|
||||
console.log('get last elem priority')
|
||||
itemdragend.newIndex = tools.getLastFirstElemPriority(itemdragend.category, itemdragend.prioritychosen, itemdragend.atfirst, itemdragend.idelemtochange)
|
||||
itemdragend.oldIndex = tools.getIndexById(itemdragend.category, itemdragend.idelemtochange)
|
||||
|
||||
console.log('swapElems PRIORITY', itemdragend)
|
||||
}
|
||||
|
||||
if (tools.isOkIndex(myarr, itemdragend.newIndex) && tools.isOkIndex(myarr, itemdragend.oldIndex)) {
|
||||
myarr.splice(itemdragend.newIndex, 0, myarr.splice(itemdragend.oldIndex, 1)[0])
|
||||
tools.notifyarraychanged(myarr[itemdragend.newIndex])
|
||||
tools.notifyarraychanged(myarr[itemdragend.oldIndex])
|
||||
|
||||
if (itemdragend.field !== 'priority') {
|
||||
const precind = itemdragend.newIndex - 1
|
||||
const nextind = itemdragend.newIndex + 1
|
||||
|
||||
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])
|
||||
}
|
||||
|
||||
} else {
|
||||
if ((myarr[precind].priority !== myarr[itemdragend.newIndex].priority)) {
|
||||
console.log(' 3)')
|
||||
myarr[itemdragend.newIndex].priority = myarr[precind].priority
|
||||
tools.notifyarraychanged(myarr[itemdragend.newIndex])
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
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)
|
||||
|
||||
// Update the records:
|
||||
}
|
||||
},
|
||||
|
||||
getIndexById(myarr, id) {
|
||||
return myarr.findIndex((elem) => elem._id === id)
|
||||
},
|
||||
|
||||
getElemById(myarr, id) {
|
||||
return myarr.find((elem) => elem._id === id)
|
||||
},
|
||||
|
||||
getElemPrevById(myarr, id) {
|
||||
return myarr.find((elem) => elem.id_prev === id)
|
||||
},
|
||||
|
||||
getLastFirstElemPriority(myarr, priority: number, atfirst: boolean, escludiId: string) {
|
||||
if (myarr === null) {
|
||||
return -1
|
||||
}
|
||||
|
||||
let trovato: boolean = false
|
||||
|
||||
console.log('priority', priority)
|
||||
|
||||
for (let indrec = 0; indrec < myarr.length; indrec++) {
|
||||
if ((myarr[indrec].priority === priority) && (myarr[indrec]._id !== escludiId)) {
|
||||
trovato = true
|
||||
if (atfirst) {
|
||||
return indrec - 1
|
||||
}
|
||||
} else {
|
||||
if (trovato) {
|
||||
return indrec
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('trovato?', trovato, 'indrec')
|
||||
|
||||
if (trovato) {
|
||||
return myarr.length - 1
|
||||
} else {
|
||||
if (priority === tools.Priority.PRIORITY_LOW) {
|
||||
return myarr.length - 1
|
||||
}
|
||||
else if (priority === tools.Priority.PRIORITY_HIGH) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
getFirstList(myarr) {
|
||||
return myarr.find((elem) => elem.id_prev === ApiTables.LIST_START)
|
||||
},
|
||||
|
||||
getLastListNotCompleted(nametable, cat) {
|
||||
let arr
|
||||
if (nametable === 'todos') {
|
||||
arr = Todos.getters.todos_dacompletare(cat)
|
||||
} else if (nametable === 'projects') {
|
||||
arr = Projects.getters.projs_dacompletare(cat)
|
||||
}
|
||||
|
||||
return (arr.length > 0) ? arr[arr.length - 1] : null
|
||||
},
|
||||
|
||||
getElemByIndex(myarr, index) {
|
||||
if (index >= 0 && index < myarr.length) {
|
||||
return myarr[index]
|
||||
}
|
||||
else {
|
||||
return null
|
||||
}
|
||||
},
|
||||
|
||||
existArr(x) {
|
||||
return x = (typeof x !== 'undefined' && x instanceof Array) ? x : []
|
||||
},
|
||||
@@ -396,6 +608,26 @@ export const tools = {
|
||||
})
|
||||
},
|
||||
|
||||
isRegistered() {
|
||||
return localStorage.getItem(tools.localStorage.userId) !== ''
|
||||
},
|
||||
|
||||
checkIfUserExist(mythis) {
|
||||
|
||||
if (UserStore.state.userId === undefined) {
|
||||
tools.showNotif(mythis.$q, mythis.$t('todo.usernotdefined'))
|
||||
return false
|
||||
}
|
||||
|
||||
if (!tools.isRegistered()) {
|
||||
// Not logged
|
||||
tools.showNotif(mythis.$q, mythis.$t('user.notregistered'))
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
|
||||
checkLangPassed(mylang) {
|
||||
|
||||
const mybrowserLang = Quasar.lang.isoName
|
||||
@@ -408,7 +640,6 @@ export const tools = {
|
||||
mylang = 'es'
|
||||
}
|
||||
|
||||
|
||||
if (!(tools.arrLangUsed.includes(mylang))) {
|
||||
console.log('non incluso ', mylang)
|
||||
mylang = tools.arrLangUsed[0]
|
||||
@@ -434,6 +665,38 @@ export const tools = {
|
||||
globalroutines(null, 'log', strlog + ' ' + strlog2 + ' ' + strlog3, null)
|
||||
},
|
||||
|
||||
/*
|
||||
get todos_vista() {
|
||||
let mystr = ''
|
||||
const arr = Todos.getters.todos_dacompletare(this.categoryAtt)
|
||||
for (const ind in arr) {
|
||||
mystr += this.getstrelem(arr[ind]) + '\n'
|
||||
}
|
||||
|
||||
return mystr + ''
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
public getArrTodos() {
|
||||
|
||||
let mystr = ''
|
||||
|
||||
return globalroutines(null, 'readall', 'todos', null)
|
||||
.then((alldata) => {
|
||||
const myrecs = [...alldata]
|
||||
|
||||
myrecs.forEach((rec) => {
|
||||
mystr = mystr + rec.descr + rec.completed + '] ['
|
||||
})
|
||||
|
||||
// this.tmpstrTodos = 'TODOS: ' + mystr
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
aspettansec(numsec) {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
@@ -458,11 +721,11 @@ export const tools = {
|
||||
})
|
||||
},
|
||||
|
||||
// _.cloneDeep( Per clonare un oggetto
|
||||
|
||||
isLoggedToSystem() {
|
||||
const tok = tools.getItemLS(tools.localStorage.token)
|
||||
return !!tok
|
||||
}
|
||||
|
||||
// _.cloneDeep( Per clonare un oggetto
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +1,53 @@
|
||||
import Vue from 'vue'
|
||||
import { Component, Watch } from 'vue-property-decorator'
|
||||
|
||||
import { IDrag, ITodo, ITodosState } from '../../../model/index'
|
||||
import { IDrag, ITodo, IProjectsState } from '../../../model/index'
|
||||
import { SingleTodo } from '../../../components/todos/SingleTodo/index'
|
||||
|
||||
import { tools } from '../../../store/Modules/tools'
|
||||
import * as ApiTables from '../../../store/Modules/ApiTables'
|
||||
|
||||
import { GlobalStore, Todos } from '@store'
|
||||
import { GlobalStore, Projects } from '@store'
|
||||
import { UserStore } from '@store'
|
||||
|
||||
import { Getter, Mutation, State } from 'vuex-class'
|
||||
const namespace: string = 'Todos'
|
||||
import { Getter } from 'vuex-class'
|
||||
|
||||
const namespace: string = 'Projects'
|
||||
|
||||
@Component({
|
||||
|
||||
components: { SingleTodo },
|
||||
filters: {
|
||||
capitalize(value) {
|
||||
if (!value) { return '' }
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
value = value.toString()
|
||||
return value.charAt(0).toUpperCase() + value.slice(1)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default class ProjList extends Vue {
|
||||
public $q: any
|
||||
public todotop: string = ''
|
||||
public todobottom: string = ''
|
||||
public polling = null
|
||||
public service: any
|
||||
public scrollable = true
|
||||
public categoryAtt: string = ''
|
||||
public dragname: string = 'second'
|
||||
|
||||
public $refs: {
|
||||
single: SingleTodo[]
|
||||
}
|
||||
|
||||
get tools() {
|
||||
return tools
|
||||
}
|
||||
|
||||
get showtype() {
|
||||
return Todos.state.showtype
|
||||
return Projects.state.showtype
|
||||
}
|
||||
|
||||
set showtype(value) {
|
||||
@@ -35,8 +55,8 @@ export default class ProjList extends Vue {
|
||||
GlobalStore.mutations.setShowType(value)
|
||||
}
|
||||
|
||||
get doneTodosCount() {
|
||||
return Todos.getters.doneTodosCount(this.categoryAtt)
|
||||
get doneProjectsCount() {
|
||||
return Projects.getters.doneProjectsCount(this.categoryAtt)
|
||||
}
|
||||
|
||||
get menuPopupConfigTodo() {
|
||||
@@ -47,73 +67,37 @@ export default class ProjList extends Vue {
|
||||
return tools.listOptionShowTask[UserStore.state.lang]
|
||||
}
|
||||
|
||||
get TodosCount() {
|
||||
return Todos.getters.TodosCount(this.categoryAtt)
|
||||
get ProjectsCount() {
|
||||
return Projects.getters.ProjectsCount(this.categoryAtt)
|
||||
}
|
||||
|
||||
// Computed:
|
||||
get reload_fromServer() {
|
||||
return Todos.state.reload_fromServer
|
||||
@Getter('projs_dacompletare', { namespace })
|
||||
public projs_dacompletare: (state: IProjectsState, category: string) => ITodo[]
|
||||
|
||||
@Getter('projs_completati', { namespace })
|
||||
public projs_completati: (state: IProjectsState, category: string) => ITodo[]
|
||||
|
||||
@Watch('$route.params.category')
|
||||
public changecat() {
|
||||
this.categoryAtt = this.$route.params.category
|
||||
}
|
||||
|
||||
set reload_fromServer(value: number) {
|
||||
Todos.state.reload_fromServer = value
|
||||
}
|
||||
public $q: any
|
||||
public filter: boolean = false
|
||||
public title: string = ''
|
||||
public todotop: string = ''
|
||||
public todobottom: string = ''
|
||||
public drag: boolean = true
|
||||
public listPriorityLabel: number[] = []
|
||||
public arrPrior: number[] = []
|
||||
public itemDragStart: any = null
|
||||
public polling = null
|
||||
public loadDone: boolean = false
|
||||
public inddragging: number = -1
|
||||
public service: any
|
||||
public actualMaxPosition: number = 15
|
||||
public scrollable = true
|
||||
public tmpstrTodos: string = ''
|
||||
public categoryAtt: string = ''
|
||||
// public showtype: number = Todos.state.showtype
|
||||
|
||||
public $refs: {
|
||||
single: SingleTodo[]
|
||||
public getmyid(id) {
|
||||
return 'row' + id
|
||||
}
|
||||
|
||||
@Getter('projList', { namespace })
|
||||
public projList: (state: ITodosState, category: string) => ITodo[]
|
||||
public showTask(field_value) {
|
||||
return field_value === tools.MenuAction.SHOW_TASK
|
||||
}
|
||||
|
||||
public async onEnd(itemdragend) {
|
||||
console.log('************ END DRAG: ', itemdragend)
|
||||
this.inddragging = -1
|
||||
|
||||
await Todos.actions.swapElems(itemdragend)
|
||||
|
||||
await Projects.actions.swapElems(itemdragend)
|
||||
}
|
||||
|
||||
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 = {
|
||||
@@ -126,12 +110,9 @@ export default class ProjList extends Vue {
|
||||
})
|
||||
|
||||
$service.eventBus.$on('drag', (el, source) => {
|
||||
// mythis.inddragging = mythis.getElementIndex(el)
|
||||
console.log('+++ DRAG ind=', this.inddragging)
|
||||
this.scrollable = false
|
||||
})
|
||||
$service.eventBus.$on('drop', (el, source) => {
|
||||
console.log('+++ DROP')
|
||||
this.scrollable = true
|
||||
})
|
||||
|
||||
@@ -139,40 +120,38 @@ export default class ProjList extends Vue {
|
||||
}
|
||||
|
||||
public mounted() {
|
||||
// console.log('*** MOUNTED ***')
|
||||
|
||||
this.categoryAtt = this.$route.params.category
|
||||
|
||||
if (window) {
|
||||
window.addEventListener('touchmove', (e) => {
|
||||
// console.log('touchmove')
|
||||
if (!this.scrollable) {
|
||||
e.preventDefault()
|
||||
}
|
||||
}, { passive: false })
|
||||
}
|
||||
}
|
||||
|
||||
public setarrPriority() {
|
||||
this.arrPrior = []
|
||||
const arr = tools.selectPriority[UserStore.state.lang]
|
||||
if (arr) {
|
||||
arr.forEach((rec) => {
|
||||
this.arrPrior.push(rec.value)
|
||||
})
|
||||
}
|
||||
// console.log('Array PRIOR:', this.arrPrior)
|
||||
tools.touchmove(this.scrollable)
|
||||
}
|
||||
|
||||
public async load() {
|
||||
console.log('LOAD TODO....')
|
||||
this.categoryAtt = this.$route.params.category
|
||||
|
||||
// Set last category selected
|
||||
localStorage.setItem(tools.localStorage.categorySel, this.categoryAtt)
|
||||
|
||||
this.checkUpdate_everytime()
|
||||
}
|
||||
|
||||
// Call to check if need to refresh
|
||||
public checkUpdate_everytime() {
|
||||
this.polling = setInterval(() => {
|
||||
this.checkUpdate()
|
||||
}, 60000)
|
||||
}
|
||||
|
||||
public beforeDestroy() {
|
||||
|
||||
clearInterval(this.polling)
|
||||
}
|
||||
|
||||
public insertTodo(atfirst: boolean = false) {
|
||||
public mydeleteItem(idobj: string) {
|
||||
// console.log('mydeleteItem', idobj)
|
||||
return Projects.actions.deleteItem({ cat: this.categoryAtt, idobj })
|
||||
}
|
||||
|
||||
public insertProject(atfirst: boolean = false) {
|
||||
let descr = this.todobottom.trim()
|
||||
if (atfirst) {
|
||||
descr = this.todotop.trim()
|
||||
@@ -182,30 +161,15 @@ export default class ProjList extends Vue {
|
||||
return
|
||||
}
|
||||
|
||||
if (UserStore.state.userId === undefined) {
|
||||
tools.showNotif(this.$q, this.$t('todo.usernotdefined'))
|
||||
if (!tools.checkIfUserExist(this)) {
|
||||
return
|
||||
}
|
||||
|
||||
// if (!this.isRegistered()) {
|
||||
// // Not logged
|
||||
// tools.showNotif(this.$q, this.$t('user.notregistered'))
|
||||
// return
|
||||
// }
|
||||
|
||||
const myobj: ITodo = {
|
||||
descr,
|
||||
category: this.categoryAtt
|
||||
}
|
||||
|
||||
return Todos.actions.insertTodo({ myobj, atfirst })
|
||||
.then((data) => {
|
||||
|
||||
console.log('data', data)
|
||||
// if (data !== null) {
|
||||
// tools.showNotif(this.$q, data)
|
||||
// }
|
||||
|
||||
// empty the field
|
||||
if (atfirst) {
|
||||
this.todotop = ''
|
||||
@@ -213,12 +177,12 @@ export default class ProjList extends Vue {
|
||||
else {
|
||||
this.todobottom = ''
|
||||
}
|
||||
})
|
||||
|
||||
return Projects.actions.insertProject({ myobj, atfirst })
|
||||
}
|
||||
|
||||
public async updateitem({ myitem, field }) {
|
||||
console.log('calling MODIFY updateitem', myitem, field)
|
||||
// Update the others components...
|
||||
|
||||
const itemdragend: IDrag = {
|
||||
category: this.categoryAtt,
|
||||
@@ -228,9 +192,9 @@ export default class ProjList extends Vue {
|
||||
atfirst: false
|
||||
}
|
||||
|
||||
await Todos.actions.swapElems(itemdragend)
|
||||
await Projects.actions.swapElems(itemdragend)
|
||||
|
||||
await Todos.actions.modify({ myitem, field })
|
||||
await Projects.actions.modify({ myitem, field })
|
||||
|
||||
}
|
||||
|
||||
@@ -256,6 +220,10 @@ export default class ProjList extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
public checkUpdate() {
|
||||
ApiTables.waitAndcheckPendingMsg()
|
||||
}
|
||||
|
||||
private getElementIndex(el: any) {
|
||||
return [].slice.call(el.parentElement.children).indexOf(el)
|
||||
}
|
||||
|
||||
@@ -56,34 +56,34 @@
|
||||
<div style="display: none">{{ prior = 0, priorcomplet = false }}</div>
|
||||
<div>
|
||||
<!--<q-infinite-scroll :handler="loadMoreTodo" :offset="7">-->
|
||||
<div class="container" v-dragula="proj_dacompletare(categoryAtt)" drake="second">
|
||||
<div :id="getmyid(mytodo._id)" :index="index"
|
||||
v-for="(mytodo, index) in proj_dacompletare(categoryAtt)"
|
||||
:key="mytodo._id" class="myitemdrag">
|
||||
<div class="container" v-dragula="projs_dacompletare(categoryAtt)" drake="second">
|
||||
<div :id="getmyid(myproj._id)" :index="index"
|
||||
v-for="(myproj, index) in projs_dacompletare(categoryAtt)"
|
||||
:key="myproj._id" class="myitemdrag">
|
||||
|
||||
<div v-if="(prior !== mytodo.priority) && !mytodo.completed"
|
||||
:class="getTitlePriority(mytodo.priority)">
|
||||
<label>{{getPriorityByInd(mytodo.priority)}}</label>
|
||||
<div v-if="(prior !== myproj.priority) && !myproj.completed"
|
||||
:class="getTitlePriority(myproj.priority)">
|
||||
<label>{{getPriorityByInd(myproj.priority)}}</label>
|
||||
</div>
|
||||
<SingleTodo ref="single" @deleteItem="mydeleteItem(mytodo._id)" @eventupdate="updateitem"
|
||||
<SingleTodo ref="single" @deleteItem="mydeleteItem(myproj._id)" @eventupdate="updateitem"
|
||||
@deselectAllRows="deselectAllRows" @onEnd="onEnd"
|
||||
:itemtodo='mytodo'/>
|
||||
:itemtodo='myproj'/>
|
||||
|
||||
<!--<div :name="`REF${index}`" class="divdrag non-draggato"></div>-->
|
||||
|
||||
<div style="display: none">{{ prior = mytodo.priority, priorcomplet = mytodo.completed }}
|
||||
<div style="display: none">{{ prior = myproj.priority, priorcomplet = myproj.completed }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--</q-infinite-scroll>-->
|
||||
|
||||
|
||||
<q-input v-if="TodosCount > 0" ref="insertTaskBottom" v-model="todobottom"
|
||||
<q-input v-if="ProjectsCount > 0" ref="insertTaskBottom" v-model="todobottom"
|
||||
style="margin-left: 6px;"
|
||||
color="blue-12"
|
||||
:label="$t('todo.insertbottom')"
|
||||
:after="[{icon: 'arrow_forward', content: true, handler () {}}]"
|
||||
v-on:keyup.enter="insertTodo(false)"/>
|
||||
v-on:keyup.enter="insertProject(false)"/>
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Vue from 'vue'
|
||||
import { Component, Watch } from 'vue-property-decorator'
|
||||
|
||||
import { ICfgServer, IDrag, IGlobalState, ITodo, ITodosState } from '../../model/index'
|
||||
import { IDrag, ITodo, ITodosState } from '../../model/index'
|
||||
import { SingleTodo } from '../../components/todos/SingleTodo/index'
|
||||
|
||||
import { tools } from '../../store/Modules/tools'
|
||||
@@ -10,9 +10,7 @@ import * as ApiTables from '../../store/Modules/ApiTables'
|
||||
import { GlobalStore, Todos } from '@store'
|
||||
import { UserStore } from '@store'
|
||||
|
||||
import { Getter, Mutation, State } from 'vuex-class'
|
||||
|
||||
import globalroutines from '../../globalroutines/index'
|
||||
import { Getter } from 'vuex-class'
|
||||
|
||||
const namespace: string = 'Todos'
|
||||
|
||||
@@ -21,15 +19,32 @@ const namespace: string = 'Todos'
|
||||
components: { SingleTodo },
|
||||
filters: {
|
||||
capitalize(value) {
|
||||
if (!value) { return '' }
|
||||
if (!value) {
|
||||
return ''
|
||||
}
|
||||
value = value.toString()
|
||||
return value.charAt(0).toUpperCase() + value.slice(1)
|
||||
}
|
||||
}
|
||||
})
|
||||
export default class Todo extends Vue {
|
||||
public $q: any
|
||||
public todotop: string = ''
|
||||
public todobottom: string = ''
|
||||
public polling = null
|
||||
public service: any
|
||||
public scrollable = true
|
||||
public categoryAtt: string = ''
|
||||
public dragname: string = 'first'
|
||||
|
||||
public $refs: {
|
||||
single: SingleTodo[]
|
||||
}
|
||||
|
||||
get tools() {
|
||||
return tools
|
||||
}
|
||||
|
||||
get showtype() {
|
||||
return Todos.state.showtype
|
||||
}
|
||||
@@ -55,54 +70,14 @@ export default class Todo extends Vue {
|
||||
return Todos.getters.TodosCount(this.categoryAtt)
|
||||
}
|
||||
|
||||
get todos_vista() {
|
||||
let mystr = ''
|
||||
const arr = Todos.getters.todos_dacompletare(this.categoryAtt)
|
||||
for (const ind in arr) {
|
||||
mystr += this.getstrelem(arr[ind]) + '\n'
|
||||
}
|
||||
|
||||
return mystr + ''
|
||||
|
||||
}
|
||||
|
||||
// Computed:
|
||||
get reload_fromServer() {
|
||||
return Todos.state.reload_fromServer
|
||||
}
|
||||
|
||||
set reload_fromServer(value: number) {
|
||||
Todos.state.reload_fromServer = value
|
||||
}
|
||||
public $q: any
|
||||
public filter: boolean = false
|
||||
public title: string = ''
|
||||
public todotop: string = ''
|
||||
public todobottom: string = ''
|
||||
public drag: boolean = true
|
||||
public listPriorityLabel: number[] = []
|
||||
public arrPrior: number[] = []
|
||||
public itemDragStart: any = null
|
||||
public polling = null
|
||||
public loadDone: boolean = false
|
||||
public inddragging: number = -1
|
||||
public service: any
|
||||
public actualMaxPosition: number = 15
|
||||
public scrollable = true
|
||||
public tmpstrTodos: string = ''
|
||||
public categoryAtt: string = ''
|
||||
|
||||
public $refs: {
|
||||
single: SingleTodo[]
|
||||
}
|
||||
|
||||
@Getter('todos_dacompletare', { namespace })
|
||||
public todos_dacompletare: (state: ITodosState, category: string) => ITodo[]
|
||||
|
||||
@Getter('todos_completati', { namespace })
|
||||
public todos_completati: (state: ITodosState, category: string) => ITodo[]
|
||||
|
||||
@Watch('$route.params.category') public changecat() {
|
||||
@Watch('$route.params.category')
|
||||
public changecat() {
|
||||
this.categoryAtt = this.$route.params.category
|
||||
}
|
||||
|
||||
@@ -114,51 +89,8 @@ export default class Todo extends Vue {
|
||||
return field_value === tools.MenuAction.SHOW_TASK
|
||||
}
|
||||
|
||||
public onStart() {
|
||||
|
||||
this.itemDragStart = null
|
||||
}
|
||||
|
||||
public logelem(mystr, elem) {
|
||||
console.log(mystr, 'elem [', elem._id, '] ', elem.descr, ' Pr(', this.getPriorityByInd(elem.priority), ') [', elem.id_prev, '] modif=', elem.modified)
|
||||
}
|
||||
|
||||
public getstrelem(elem) {
|
||||
return 'elem [' + elem._id + '] ' + elem.descr + ' Pr(' + this.getPriorityByInd(elem.priority) + ') [ID_PREV=' + elem.id_prev + '] modif=' + elem.modified + ' '
|
||||
}
|
||||
|
||||
public getTitlePriority(priority) {
|
||||
let cl = ''
|
||||
|
||||
if (priority === tools.Priority.PRIORITY_HIGH) {
|
||||
cl = 'high_priority'
|
||||
}
|
||||
else if (priority === tools.Priority.PRIORITY_NORMAL) {
|
||||
cl = 'medium_priority'
|
||||
}
|
||||
else if (priority === tools.Priority.PRIORITY_LOW) {
|
||||
cl = 'low_priority'
|
||||
}
|
||||
|
||||
return cl + ' titlePriority'
|
||||
}
|
||||
|
||||
public logga_arr(myarr: ITodo[]) {
|
||||
let mystr = '\n'
|
||||
myarr.forEach((item) => {
|
||||
mystr += '[' + item.pos + '] ' + item.descr + ' Pr(' + this.getPriorityByInd(item.priority) + ') [' + item.id_prev + '] modif=' + item.modified + '\n'
|
||||
// mystr += '[' + item.pos + '] ' + item.descr + '\n'
|
||||
})
|
||||
|
||||
return mystr
|
||||
}
|
||||
|
||||
public async onEnd(itemdragend) {
|
||||
console.log('************ END DRAG: ', itemdragend)
|
||||
this.inddragging = -1
|
||||
|
||||
await Todos.actions.swapElems(itemdragend)
|
||||
|
||||
}
|
||||
|
||||
public created() {
|
||||
@@ -177,12 +109,9 @@ export default class Todo extends Vue {
|
||||
})
|
||||
|
||||
$service.eventBus.$on('drag', (el, source) => {
|
||||
// mythis.inddragging = mythis.getElementIndex(el)
|
||||
console.log('+++ DRAG ind=', this.inddragging)
|
||||
this.scrollable = false
|
||||
})
|
||||
$service.eventBus.$on('drop', (el, source) => {
|
||||
console.log('+++ DROP')
|
||||
this.scrollable = true
|
||||
})
|
||||
|
||||
@@ -190,29 +119,9 @@ export default class Todo extends Vue {
|
||||
}
|
||||
|
||||
public mounted() {
|
||||
// console.log('*** MOUNTED ***')
|
||||
|
||||
this.categoryAtt = this.$route.params.category
|
||||
|
||||
if (window) {
|
||||
window.addEventListener('touchmove', (e) => {
|
||||
// console.log('touchmove')
|
||||
if (!this.scrollable) {
|
||||
e.preventDefault()
|
||||
}
|
||||
}, { passive: false })
|
||||
}
|
||||
}
|
||||
|
||||
public setarrPriority() {
|
||||
this.arrPrior = []
|
||||
const arr = tools.selectPriority[UserStore.state.lang]
|
||||
if (arr) {
|
||||
arr.forEach((rec) => {
|
||||
this.arrPrior.push(rec.value)
|
||||
})
|
||||
}
|
||||
// console.log('Array PRIOR:', this.arrPrior)
|
||||
tools.touchmove(this.scrollable)
|
||||
}
|
||||
|
||||
public async load() {
|
||||
@@ -222,16 +131,7 @@ export default class Todo extends Vue {
|
||||
// Set last category selected
|
||||
localStorage.setItem(tools.localStorage.categorySel, this.categoryAtt)
|
||||
|
||||
for (const todosKey in tools.Priority) {
|
||||
this.listPriorityLabel.push(tools.Priority[todosKey])
|
||||
}
|
||||
// console.log('Priority:' + this.listPriorityLabel)
|
||||
this.setarrPriority()
|
||||
|
||||
this.loadDone = true
|
||||
|
||||
this.checkUpdate_everytime()
|
||||
|
||||
}
|
||||
|
||||
// Call to check if need to refresh
|
||||
@@ -245,25 +145,6 @@ export default class Todo extends Vue {
|
||||
clearInterval(this.polling)
|
||||
}
|
||||
|
||||
public getPriorityByInd(index) {
|
||||
// console.log('LANG in PRIOR', UserStore.state.lang)
|
||||
try {
|
||||
const arr = tools.selectPriority[UserStore.state.lang]
|
||||
for (const rec of arr) {
|
||||
if (rec.value === index) {
|
||||
return rec.label
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
public isRegistered() {
|
||||
return localStorage.getItem(tools.localStorage.userId) !== ''
|
||||
}
|
||||
|
||||
public mydeleteItem(idobj: string) {
|
||||
// console.log('mydeleteItem', idobj)
|
||||
return Todos.actions.deleteItem({ cat: this.categoryAtt, idobj })
|
||||
@@ -279,14 +160,7 @@ export default class Todo extends Vue {
|
||||
return
|
||||
}
|
||||
|
||||
if (UserStore.state.userId === undefined) {
|
||||
tools.showNotif(this.$q, this.$t('todo.usernotdefined'))
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.isRegistered()) {
|
||||
// Not logged
|
||||
tools.showNotif(this.$q, this.$t('user.notregistered'))
|
||||
if (!tools.checkIfUserExist(this)) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -308,7 +182,6 @@ export default class Todo extends Vue {
|
||||
|
||||
public async updateitem({ myitem, field }) {
|
||||
console.log('calling MODIFY updateitem', myitem, field)
|
||||
// Update the others components...
|
||||
|
||||
const itemdragend: IDrag = {
|
||||
category: this.categoryAtt,
|
||||
@@ -350,31 +223,6 @@ export default class Todo extends Vue {
|
||||
ApiTables.waitAndcheckPendingMsg()
|
||||
}
|
||||
|
||||
public loadMoreTodo(index, done) {
|
||||
setTimeout(() => {
|
||||
this.actualMaxPosition += 15
|
||||
done()
|
||||
}, 100)
|
||||
|
||||
}
|
||||
|
||||
public getArrTodos() {
|
||||
|
||||
let mystr = ''
|
||||
|
||||
this.tmpstrTodos = ''
|
||||
return globalroutines(null, 'readall', 'todos', null)
|
||||
.then((alldata) => {
|
||||
const myrecs = [...alldata]
|
||||
|
||||
myrecs.forEach((rec) => {
|
||||
mystr = mystr + rec.descr + rec.completed + '] ['
|
||||
})
|
||||
|
||||
this.tmpstrTodos = 'TODOS: ' + mystr
|
||||
})
|
||||
}
|
||||
|
||||
private getElementIndex(el: any) {
|
||||
return [].slice.call(el.parentElement.children).indexOf(el)
|
||||
}
|
||||
|
||||
@@ -69,8 +69,8 @@
|
||||
:key="mytodo._id" class="myitemdrag">
|
||||
|
||||
<div v-if="(prior !== mytodo.priority) && !mytodo.completed"
|
||||
:class="getTitlePriority(mytodo.priority)">
|
||||
<label>{{getPriorityByInd(mytodo.priority)}}</label>
|
||||
:class="tools.getTitlePriority(mytodo.priority)">
|
||||
<label>{{tools.getPriorityByInd(mytodo.priority)}}</label>
|
||||
</div>
|
||||
<SingleTodo ref="single" @deleteItem="mydeleteItem(mytodo._id)" @eventupdate="updateitem"
|
||||
@deselectAllRows="deselectAllRows" @onEnd="onEnd"
|
||||
|
||||
Reference in New Issue
Block a user