From 2ba3cd6b3f488935fb45a422885051db96f8e166 Mon Sep 17 00:00:00 2001 From: Paolo Arena Date: Sat, 27 Apr 2019 20:12:41 +0200 Subject: [PATCH] Move Project --- src-pwa/custom-service-worker.js | 6 +- .../projects/SingleProject/SingleProject.ts | 8 +- src/model/Projects.ts | 6 ++ src/statics/i18n.js | 3 + src/store/Modules/ApiTables.ts | 16 +++- src/store/Modules/GlobalStore.ts | 15 ++-- src/store/Modules/Projects.ts | 58 +++++++++++-- src/store/Modules/tools.ts | 86 ++++++++++++++++++- src/store/Modules/translation.ts | 9 ++ src/views/projects/proj-list/proj-list.ts | 20 ++++- src/views/projects/proj-list/proj-list.vue | 16 +++- 11 files changed, 217 insertions(+), 26 deletions(-) diff --git a/src-pwa/custom-service-worker.js b/src-pwa/custom-service-worker.js index a59cfe4..eea2df5 100644 --- a/src-pwa/custom-service-worker.js +++ b/src-pwa/custom-service-worker.js @@ -6,11 +6,13 @@ // Questo è il swSrc -console.log(' [ VER-0.0.27 ] _---------________------ PAO: this is my custom service worker'); +console.log(' [ VER-0.0.61 ] _---------________------ PAO: this is my custom service worker'); importScripts('../statics/js/idb.js'); importScripts('../statics/js/storage.js'); -importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js'); //++Todo: Replace with local workbox.js +importScripts('../statics/js/workbox-sw.js'); + +// importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js'); let port = 3000; diff --git a/src/components/projects/SingleProject/SingleProject.ts b/src/components/projects/SingleProject/SingleProject.ts index 0450c20..ebaade5 100644 --- a/src/components/projects/SingleProject/SingleProject.ts +++ b/src/components/projects/SingleProject/SingleProject.ts @@ -324,7 +324,7 @@ export default class SingleProject extends Vue { } // console.log('focus()') - }, 500) + }, 400) } public getFocus(e) { @@ -486,6 +486,12 @@ export default class SingleProject extends Vue { return await this.enableExpiring() } else if (action === tools.MenuAction.EDIT) { this.activeEdit() + } else if (action === tools.MenuAction.CUT) { + const myaction = { + type: tools.MenuAction.CUT, + _id: this.itemproject._id + } + return await Projects.actions.ActionCutPaste(myaction) } else if (action === 0) { this.deselectAndExitEdit() } diff --git a/src/model/Projects.ts b/src/model/Projects.ts index 1c54131..b1ce295 100644 --- a/src/model/Projects.ts +++ b/src/model/Projects.ts @@ -2,6 +2,11 @@ import objectId from '@src/js/objectId' import { UserStore } from '@store' import { tools } from '@src/store/Modules/tools' +export interface IAction { + type: number + _id: any +} + export interface IProject { _id?: any, userId?: string @@ -43,6 +48,7 @@ export interface IProjectsState { projects: IProject[] insidePending: boolean visuLastCompleted: number + action: IAction } export const Privacy = { diff --git a/src/statics/i18n.js b/src/statics/i18n.js index ba2770a..7b8bba9 100644 --- a/src/statics/i18n.js +++ b/src/statics/i18n.js @@ -246,6 +246,7 @@ const messages = { proj: { newproj: 'Titolo Progetto', newsubproj: 'Titolo Sotto-Progetto', + insertbottom: 'Inserisci Nuovo Project', longdescr: 'Descrizione', hoursplanned: 'Ore Preventivate', hoursadded: 'Ore Aggiuntive', @@ -502,6 +503,7 @@ const messages = { proj: { newproj: 'Título Projecto', newsubproj: 'Título Sub-Projecto', + insertbottom: 'Añadir nuevo Proyecto', longdescr: 'Descripción', hoursplanned: 'Horas Estimadas', hoursadded: 'Horas Adicional', @@ -758,6 +760,7 @@ const messages = { proj: { newproj: 'Project Title', newsubproj: 'SubProject Title', + insertbottom: 'Insert New Project', longdescr: 'Description', hoursplanned: 'Estimated Hours', hoursadded: 'Additional Hours', diff --git a/src/store/Modules/ApiTables.ts b/src/store/Modules/ApiTables.ts index 971258d..32123dd 100644 --- a/src/store/Modules/ApiTables.ts +++ b/src/store/Modules/ApiTables.ts @@ -108,14 +108,22 @@ async function Sync_Execute(cmd, tablesync, nametab, method, item: ITodo, id, ms cmdSw = DB.CMD_SYNC } + // console.log('cmdSw', cmdSw) + + // if ('serviceWorker' in navigator) { + // console.log('serviceWorker PRESENTE') + // } else { + // console.log('serviceWorker NON PRESENTE !') + // } + if ('serviceWorker' in navigator) { return await navigator.serviceWorker.ready .then((sw) => { // console.log('---------------------- navigator.serviceWorker.ready') return globalroutines(null, 'write', tablesync, item, id) - .then((id) => { - // console.log('id', id) + .then((ris) => { + console.log('ris write:', ris) const sep = '|' const multiparams = cmdSw + sep + tablesync + sep + nametab + sep + method + sep + UserStore.state.x_auth_token + sep + UserStore.state.lang @@ -145,6 +153,9 @@ async function Sync_Execute(cmd, tablesync, nametab, method, item: ITodo, id, ms console.error('Errore in globalroutines', tablesync, nametab, err) }) }) + .catch((err) => { + console.error('Errore catch in globalroutines write', tablesync, nametab, err) + }) }) } } @@ -408,6 +419,7 @@ export async function table_ModifyRecord(nametable, myitem, listFieldsToChange, tools.notifyarraychanged(miorec) // 2) Modify on IndexedDb + console.log('// 2) Modify on IndexedDb', miorec) return globalroutines(null, 'write', nametable, miorec) .then((ris) => { diff --git a/src/store/Modules/GlobalStore.ts b/src/store/Modules/GlobalStore.ts index 2282428..e718f66 100644 --- a/src/store/Modules/GlobalStore.ts +++ b/src/store/Modules/GlobalStore.ts @@ -181,15 +181,12 @@ namespace Getters { addRoute(arrroutes, { route: '/', faIcon: 'fa fa-home', materialIcon: 'home', name: 'pages.home' }) // HOME - if (!process.env.PROD) { - addRoute(arrroutes, { - route: '/todo', faIcon: 'fa fa-list-alt', materialIcon: 'format_list_numbered', name: 'pages.Todo', - routes2: lista, - level_parent: 0.5, - level_child: 0.5 - }) - - } + addRoute(arrroutes, { + route: '/todo', faIcon: 'fa fa-list-alt', materialIcon: 'format_list_numbered', name: 'pages.Todo', + routes2: lista, + level_parent: 0.5, + level_child: 0.5 + }) const myarrproj = [] for (const myitem of listaprojectMenu) { diff --git a/src/store/Modules/Projects.ts b/src/store/Modules/Projects.ts index 4fbc520..20c0a43 100644 --- a/src/store/Modules/Projects.ts +++ b/src/store/Modules/Projects.ts @@ -1,4 +1,4 @@ -import { IProject, IProjectsState, IDrag, IMenuList } from 'model' +import { IProject, IProjectsState, IDrag, IMenuList, IAction } from 'model' import { Privacy } from '@src/model' import { storeBuilder } from './Store/Store' @@ -18,7 +18,11 @@ const stateglob: IProjectsState = { showtype: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED, projects: [], insidePending: false, - visuLastCompleted: 10 + visuLastCompleted: 10, + action: { + type: 0, + _id: '' + } } const listFieldsToChange: string [] = ['descr', 'longdescr', 'hoursplanned', 'hoursworked', 'id_parent', 'statusproj', @@ -94,7 +98,7 @@ namespace Getters { begin_development: tools.getDateNull(), begin_test: tools.getDateNull(), hoursweeky_plannedtowork: 0, - endwork_estimate: tools.getDateNull() + endwork_estimate: tools.getDateNull(), } return obj @@ -240,10 +244,23 @@ namespace Mutations { ApiTables.removeitemfromarray(state.projects, ind) } + async function movemyitem(state: IProjectsState, { myitemorig, myitemdest } ) { + const indorig = tools.getIndexById(state.projects, myitemorig._id) + + // console.log('myitemorig', myitemorig, 'indorig', indorig) + // console.log('myitemdest', myitemdest) + + state.projects.splice(indorig, 1) + state.projects.push(myitemdest) + + await Actions.actions.modify({ myitem: myitemdest, field: 'id_parent' }) + } + export const mutations = { deletemyitem: b.commit(deletemyitem), createNewItem: b.commit(createNewItem), - updateProject: b.commit(updateProject) + updateProject: b.commit(updateProject), + movemyitem: b.commit(movemyitem) } } @@ -380,12 +397,43 @@ namespace Actions { } + async function ActionCutPaste(context, action: IAction) { + + if (action.type === tools.MenuAction.CUT) + stateglob.action = action + else if (action.type === tools.MenuAction.PASTE) { + if (stateglob.action.type === tools.MenuAction.CUT) { + + // Change id_parent + const orig_obj = Getters.getters.getRecordById(stateglob.action._id) + const dest = Getters.getters.getRecordById(action._id) + + // console.log('dest', dest) + + const dest_obj = tools.jsonCopy(orig_obj) + + if (!!dest_obj) { + dest_obj.id_parent = dest._id + dest_obj.id_main_project = dest.id_main_project + dest_obj.modified = true + dest_obj.id_prev = null + + await Mutations.mutations.movemyitem({ myitemorig: orig_obj, myitemdest: dest_obj }) + } + + stateglob.action.type = 0 + } + } + return true + } + export const actions = { dbLoad: b.dispatch(dbLoad), swapElems: b.dispatch(swapElems), deleteItem: b.dispatch(deleteItem), dbInsert: b.dispatch(dbInsert), - modify: b.dispatch(modify) + modify: b.dispatch(modify), + ActionCutPaste: b.dispatch(ActionCutPaste) } } diff --git a/src/store/Modules/tools.ts b/src/store/Modules/tools.ts index 4572561..66e8dd6 100644 --- a/src/store/Modules/tools.ts +++ b/src/store/Modules/tools.ts @@ -61,6 +61,8 @@ export const tools = { }, MenuAction: { + CUT: 71, + PASTE: 72, DELETE: 100, TOGGLE_EXPIRING: 101, COMPLETED: 110, @@ -480,6 +482,12 @@ export const tools = { menuPopupProj: { it: [ + { + id: 5, + label: 'Taglia', + value: 71, // CUT + icon: 'undo' + }, { id: 10, label: 'Modifica', @@ -503,6 +511,12 @@ export const tools = { ], es: [ + { + id: 5, + label: 'Cortar', + value: 71, // CUT + icon: 'undo' + }, { id: 10, label: 'Editar', @@ -526,6 +540,12 @@ export const tools = { ], enUs: [ + { + id: 5, + label: 'Cut', + value: 71, // CUT + icon: 'undo' + }, { id: 10, label: 'Edit', @@ -582,14 +602,23 @@ export const tools = { menuPopupConfigProject: { it: [ + { + id: 3, + disable: false, + label: translation.it.action.paste, + value: 72, // Action.PASTE + icon: 'file_copy' + }, { id: 5, + disable: false, label: translation.it.proj.newsubproj, value: 200, // ADD_PROJECT icon: 'next_week' }, { id: 10, + disable: false, label: translation.it.task.showtask, value: 150, // SHOW_TASK icon: 'rowing' @@ -597,14 +626,23 @@ export const tools = { ], es: [ + { + id: 3, + disable: false, + label: translation.es.action.paste, + value: 72, // Action.PASTE + icon: 'file_copy' + }, { id: 5, + disable: false, label: translation.es.proj.newsubproj, value: 200, // ADD_PROJECT icon: 'next_week' }, { id: 10, + disable: false, label: translation.es.task.showtask, value: 150, icon: 'rowing' @@ -612,14 +650,23 @@ export const tools = { ], enUs: [ + { + id: 3, + disable: false, + label: translation.enUs.action.paste, + value: 72, // Action.PASTE + icon: 'file_copy' + }, { id: 5, - label: translation.it.proj.newsubproj, + disable: false, + label: translation.enUs.proj.newsubproj, value: 200, // ADD_PROJECT icon: 'next_week' }, { id: 10, + disable: false, label: translation.enUs.task.showtask, value: 150, icon: 'rowing' @@ -629,8 +676,16 @@ export const tools = { menuPopupConfigMAINProject: { it: [ + { + id: 3, + disable: false, + label: translation.it.action.paste, + value: 72, // Action.PASTE + icon: 'file_copy' + }, { id: 5, + disable: false, label: translation.it.proj.newproj, value: 200, // ADD_PROJECT icon: 'next_week' @@ -638,8 +693,16 @@ export const tools = { ], es: [ + { + id: 3, + disable: false, + label: translation.es.action.paste, + value: 72, // Action.PASTE + icon: 'file_copy' + }, { id: 5, + disable: false, label: translation.es.proj.newproj, value: 200, // ADD_PROJECT icon: 'next_week' @@ -647,9 +710,17 @@ export const tools = { ], enUs: [ + { + id: 3, + disable: false, + label: translation.enUs.action.paste, + value: 72, // Action.PASTE + icon: 'file_copy' + }, { id: 5, - label: translation.it.proj.newproj, + disable: false, + label: translation.enUs.proj.newproj, value: 200, // ADD_PROJECT icon: 'next_week' } @@ -660,6 +731,7 @@ export const tools = { it: [ { id: 10, + disable: false, label: 'Mostra gli ultimi N completati', value: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED, icon: 'rowing', @@ -667,6 +739,7 @@ export const tools = { }, { id: 20, + disable: false, label: 'Compiti da Completare', value: costanti.ShowTypeTask.SHOW_ONLY_TOCOMPLETE, icon: 'rowing', @@ -674,6 +747,7 @@ export const tools = { }, { id: 30, + disable: false, label: 'Tutti i compiti', value: costanti.ShowTypeTask.SHOW_ALL, icon: 'check_circle', @@ -684,6 +758,7 @@ export const tools = { [ { id: 10, + disable: false, label: 'Mostrar los ultimos N completados', value: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED, icon: 'rowing', @@ -691,6 +766,7 @@ export const tools = { }, { id: 20, + disable: false, label: 'Tareas para completar', value: costanti.ShowTypeTask.SHOW_ONLY_TOCOMPLETE, icon: 'rowing', @@ -698,6 +774,7 @@ export const tools = { }, { id: 30, + disable: false, label: 'Todos las Tareas', value: costanti.ShowTypeTask.SHOW_ALL, icon: 'check_circle', @@ -708,6 +785,7 @@ export const tools = { [ { id: 10, + disable: false, label: 'Show last N Completed', value: costanti.ShowTypeTask.SHOW_LAST_N_COMPLETED, icon: 'rowing', @@ -715,6 +793,7 @@ export const tools = { }, { id: 20, + disable: false, label: 'Task to complete', value: costanti.ShowTypeTask.SHOW_ONLY_TOCOMPLETE, icon: 'rowing', @@ -722,6 +801,7 @@ export const tools = { }, { id: 30, + disable: false, label: 'All Tasks', value: costanti.ShowTypeTask.SHOW_ALL, icon: 'check_circle', @@ -1405,6 +1485,6 @@ export const tools = { lista.push(item) } return lista - } + }, } diff --git a/src/store/Modules/translation.ts b/src/store/Modules/translation.ts index b848c80..8fc01c7 100644 --- a/src/store/Modules/translation.ts +++ b/src/store/Modules/translation.ts @@ -14,6 +14,9 @@ export const translation = { task: { showtask: 'Mostra Task', }, + action: { + paste: 'Incolla' + }, end: '' }, es: { @@ -31,6 +34,9 @@ export const translation = { task: { showtask: 'Mostrar Tarea', }, + action: { + paste: 'Pegar' + }, end: '' }, enUs: { @@ -48,6 +54,9 @@ export const translation = { task: { showtask: 'Show Task', }, + action: { + paste: 'Paste' + }, end: '' } } diff --git a/src/views/projects/proj-list/proj-list.ts b/src/views/projects/proj-list/proj-list.ts index 286c4fb..db14c65 100644 --- a/src/views/projects/proj-list/proj-list.ts +++ b/src/views/projects/proj-list/proj-list.ts @@ -1,7 +1,7 @@ import Vue from 'vue' import { Component, Watch } from 'vue-property-decorator' -import { IDrag, IProject, IProjectsState, ITodo, Privacy, TypeProj } from '../../../model/index' +import { IAction, IDrag, IProject, IProjectsState, ITodo, Privacy, TypeProj } from '../../../model/index' import { SingleProject } from '../../../components/projects/SingleProject/index' import { CTodo } from '../../../components/todos/CTodo' @@ -164,10 +164,16 @@ export default class ProjList extends Vue { } get menuPopupConfigProject() { + let mymenu = null if (this.isMainProject) - return tools.menuPopupConfigMAINProject[UserStore.state.lang] + mymenu = tools.menuPopupConfigMAINProject[UserStore.state.lang] else - return tools.menuPopupConfigProject[UserStore.state.lang] + mymenu = tools.menuPopupConfigProject[UserStore.state.lang] + + if (mymenu.length > 0) + mymenu[0].disable = !(Projects.state.action.type === tools.MenuAction.CUT) + + return mymenu } get listOptionShowTask() { @@ -370,6 +376,14 @@ export default class ProjList extends Vue { // @ts-ignore elem.activeEdit() // console.log('idnewelem', idnewelem, 'Elem Trovato', elem) + } else if (action === tools.MenuAction.PASTE) { + + const myaction: IAction = { + type: tools.MenuAction.PASTE, + _id: this.itemselproj._id + } + + return await Projects.actions.ActionCutPaste(myaction) } } diff --git a/src/views/projects/proj-list/proj-list.vue b/src/views/projects/proj-list/proj-list.vue index bd336a2..82c2a06 100644 --- a/src/views/projects/proj-list/proj-list.vue +++ b/src/views/projects/proj-list/proj-list.vue @@ -61,7 +61,7 @@ - @@ -100,6 +100,20 @@ + + + + +
+ + + +