Commit fb63d69c authored by Project Open's avatar Project Open

- Created a HourWeeklyProxy between panel and HoursStore.

parent b9c62c43
...@@ -32,6 +32,7 @@ Ext.require([ ...@@ -32,6 +32,7 @@ Ext.require([
'PO.store.timesheet.TaskTreeStore', 'PO.store.timesheet.TaskTreeStore',
'PO.tsweekly.HourWeeklyController', 'PO.tsweekly.HourWeeklyController',
'PO.tsweekly.HourWeekly', 'PO.tsweekly.HourWeekly',
'PO.tsweekly.HourWeeklyProxy',
'PO.tsweekly.HourWeeklyStore', 'PO.tsweekly.HourWeeklyStore',
'PO.view.field.POComboTree' 'PO.view.field.POComboTree'
]); ]);
...@@ -40,6 +41,7 @@ function launchTimesheetWeeklyLogging(){ ...@@ -40,6 +41,7 @@ function launchTimesheetWeeklyLogging(){
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// Stores // Stores
var hourStore = Ext.StoreManager.get('hourStore'); var hourStore = Ext.StoreManager.get('hourStore');
var hourWeeklyStore = Ext.StoreManager.get('hourWeeklyStore');
var taskTreeStore = Ext.StoreManager.get('taskTreeStore'); var taskTreeStore = Ext.StoreManager.get('taskTreeStore');
var projectStore = Ext.StoreManager.get('projectMainStore'); var projectStore = Ext.StoreManager.get('projectMainStore');
...@@ -75,7 +77,7 @@ function launchTimesheetWeeklyLogging(){ ...@@ -75,7 +77,7 @@ function launchTimesheetWeeklyLogging(){
}; };
var hourGrid = Ext.create('Ext.grid.Panel', { var hourGrid = Ext.create('Ext.grid.Panel', {
store: hourStore, store: hourWeeklyStore,
layout: 'fit', layout: 'fit',
region: 'center', region: 'center',
columnLines: true, columnLines: true,
...@@ -134,26 +136,30 @@ function launchTimesheetWeeklyLogging(){ ...@@ -134,26 +136,30 @@ function launchTimesheetWeeklyLogging(){
}, },
editor: { xtype: 'pocombotree', store: taskTreeStore, queryMode: 'local', displayField: 'project_name', valueField: 'id'} editor: { xtype: 'pocombotree', store: taskTreeStore, queryMode: 'local', displayField: 'project_name', valueField: 'id'}
}, },
{text: "<div align=center>Mon<br>3/29/2021</div>", width: 65, align: "right", dataIndex: 'hours', {text: "<div align=center>Mon<br>3/29/2021</div>", width: 65, align: "right", dataIndex: 'hours_0',
editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer}, editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer},
{text: "<div align=center>Tue<br>3/30/2021</div>", width: 65, align: "right", dataIndex: 'hours', {text: "<div align=center>Tue<br>3/30/2021</div>", width: 65, align: "right", dataIndex: 'hours_1',
editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer}, editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer},
{text: "<div align=center>Wed<br>2/31/2021</div>", width: 65, align: "right", dataIndex: 'hours', {text: "<div align=center>Wed<br>2/31/2021</div>", width: 65, align: "right", dataIndex: 'hours_2',
editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer}, editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer},
{text: "<div align=center>Thu<br>2/31/2021</div>", width: 65, align: "right", dataIndex: 'hours', {text: "<div align=center>Thu<br>2/31/2021</div>", width: 65, align: "right", dataIndex: 'hours_3',
editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer}, editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer},
{text: "<div align=center>Fri<br>2/31/2021</div>", width: 65, align: "right", dataIndex: 'hours', {text: "<div align=center>Fri<br>2/31/2021</div>", width: 65, align: "right", dataIndex: 'hours_4',
editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer}, editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer},
{text: "<div align=center>Sat<br>2/31/2021</div>", width: 65, align: "right", dataIndex: 'hours', {text: "<div align=center>Sat<br>2/31/2021</div>", width: 65, align: "right", dataIndex: 'hours_5',
editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer}, editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer},
{text: "<div align=center>Sun<br>2/31/2021</div>", width: 65, align: "right", dataIndex: 'hours', {text: "<div align=center>Sun<br>2/31/2021</div>", width: 65, align: "right", dataIndex: 'hours_6',
editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer}, editor: { xtype: 'numberfield', minValue: 0}, summaryType: sumType, summaryRenderer: sumRenderer},
{ text: "Sum", width: 65, dataIndex: 'note', align: "center", { text: "Sum", width: 65, dataIndex: 'note', align: "center",
renderer: function(value, metaData, record, rowIndex, colIndex, store, view) { renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
var hoursString = record.get('hours'); var sum = 0.0;
var hoursFloat = parseFloat(hoursString) for (var i = 0; i < 7; i++) {
if ("number" == typeof(hoursFloat)) return Math.round(700.0 * hoursFloat) / 100.0; var hoursString = record.get('hours_'+i);
return ""; var hoursFloat = parseFloat(hoursString);
var type = typeof(hoursFloat);
if ("number" == type && !!hoursFloat) sum = sum + hoursFloat;
}
return Math.round(100.0 * sum) / 100.0;
}, },
summaryType: function(hourArray, dataIndex) { summaryType: function(hourArray, dataIndex) {
var sum = 0; var sum = 0;
...@@ -208,6 +214,8 @@ function launchTimesheetWeeklyLogging(){ ...@@ -208,6 +214,8 @@ function launchTimesheetWeeklyLogging(){
var hourController = Ext.create('PO.tsweekly.HourWeeklyController', { var hourController = Ext.create('PO.tsweekly.HourWeeklyController', {
'hourButtonPanel': hourButtonPanel, 'hourButtonPanel': hourButtonPanel,
'taskTreeStore': taskTreeStore, 'taskTreeStore': taskTreeStore,
'rowEditing': rowEditing,
'hourWeeklyStore': hourWeeklyStore,
'hourGrid': hourGrid 'hourGrid': hourGrid
}); });
hourController.init(this).onLaunch(this); hourController.init(this).onLaunch(this);
...@@ -236,6 +244,7 @@ Ext.onReady(function() { ...@@ -236,6 +244,7 @@ Ext.onReady(function() {
var debug = PO.Utilities.getDebug('default'); var debug = PO.Utilities.getDebug('default');
var taskTreeStore = Ext.create('PO.store.timesheet.TaskTreeStore'); var taskTreeStore = Ext.create('PO.store.timesheet.TaskTreeStore');
var hourStore = Ext.create('PO.store.timesheet.HourStore'); var hourStore = Ext.create('PO.store.timesheet.HourStore');
var hourWeeklyStore = Ext.create('PO.tsweekly.HourWeeklyStore');
var projectStore = Ext.create('PO.store.project.ProjectMainStore'); var projectStore = Ext.create('PO.store.project.ProjectMainStore');
// Use a "store coodinator" in order to launchTimesheetWeeklyLogging() only // Use a "store coodinator" in order to launchTimesheetWeeklyLogging() only
......
Ext.define('PO.tsweekly.HourWeekly', { Ext.define('PO.tsweekly.HourWeekly', {
extend: 'Ext.data.Model', extend: 'Ext.data.Model',
fields: [ fields: [
...@@ -15,6 +16,15 @@ Ext.define('PO.tsweekly.HourWeekly', { ...@@ -15,6 +16,15 @@ Ext.define('PO.tsweekly.HourWeekly', {
'hours_4', // How many hours were logged? 'hours_4', // How many hours were logged?
'hours_5', // How many hours were logged? 'hours_5', // How many hours were logged?
'hours_6' // How many hours were logged? 'hours_6' // How many hours were logged?
] ],
// proxy: { type: 'hourWeeklyProxy' }
/* proxy: {
type: 'hourWeeklyProxy',
reader: {
type: 'json',
root: 'users'
}
}
*/
}); });
...@@ -11,11 +11,13 @@ Ext.define('PO.tsweekly.HourWeeklyController', { ...@@ -11,11 +11,13 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
hourController: null, hourController: null,
hourGrid: null, hourGrid: null,
taskTreeStore: null, taskTreeStore: null,
rowEditing: null,
hourWeeklyStore: null,
// Setup the various listeners to receive events here // Setup the various listeners to receive events here
init: function() { init: function() {
var me = this; var me = this;
if (me.debug) { console.log('PO.tsweekly.HourWeeklyController: init'); } if (me.debug) { console.log('PO.tsweekly.HourWeeklyController.init: Starting'); }
this.control({ this.control({
'#buttonAddEntry': { click: this.onButtonAddEntry }, '#buttonAddEntry': { click: this.onButtonAddEntry },
...@@ -29,12 +31,13 @@ Ext.define('PO.tsweekly.HourWeeklyController', { ...@@ -29,12 +31,13 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
// Trying to crate a "change" event from the Project combo, // Trying to crate a "change" event from the Project combo,
// but this didn't work. Now just hard-wiring... // but this didn't work. Now just hard-wiring...
var rowEditing = me.hourGrid.editingPlugin; // ToDo
// Catch a global key strokes. This is used to abort entry with Esc. // Catch a global key strokes. This is used to abort entry with Esc.
// For some reaons this doesn't work on the level of the HourButtonPanel, so we go for the global "window" // For some reaons this doesn't work on the level of the HourButtonPanel, so we go for the global "window"
Ext.EventManager.on(window, 'keydown', this.onWindowKeyDown, me); Ext.EventManager.on(window, 'keydown', this.onWindowKeyDown, me);
if (me.debug) { console.log('PO.tsweekly.HourWeeklyController.init: Finished'); }
return this; return this;
}, },
...@@ -70,10 +73,12 @@ Ext.define('PO.tsweekly.HourWeeklyController', { ...@@ -70,10 +73,12 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
* fills in the end_time. * fills in the end_time.
*/ */
onGridBeforeEdit: function(editor, context, eOpts) { onGridBeforeEdit: function(editor, context, eOpts) {
console.log('GanttButtonController.onGridBeforeEdit'); var me = this;
if (me.debug) console.log('HourWeeklyController.onGridBeforeEdit: Starting');
// console.log(context.record); // console.log(context.record);
// Return true to indicate to the editor that it's OK to edit // Return true to indicate to the editor that it's OK to edit
if (me.debug) console.log('HourWeeklyController.onGridBeforeEdit: Finished');
return true; return true;
}, },
...@@ -81,7 +86,8 @@ Ext.define('PO.tsweekly.HourWeeklyController', { ...@@ -81,7 +86,8 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
* Gets called after finishing an edit using the "Update" button * Gets called after finishing an edit using the "Update" button
*/ */
onGridEdit: function(editor, context) { onGridEdit: function(editor, context) {
console.log('GanttButtonController.onGridEdit'); var me = this;
if (me.debug) console.log('HourWeeklyController.onGridEdit: Starting');
var rec = context.record; var rec = context.record;
var interval_date = rec.get('interval_date'); var interval_date = rec.get('interval_date');
...@@ -123,13 +129,14 @@ Ext.define('PO.tsweekly.HourWeeklyController', { ...@@ -123,13 +129,14 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
rec.save(); rec.save();
rec.commit(); rec.commit();
if (me.debug) console.log('HourWeeklyController.onGridEdit: Finished');
}, },
// Esc (Escape) button pressed somewhere in the application window // Esc (Escape) button pressed somewhere in the application window
onWindowKeyDown: function(e) { onWindowKeyDown: function(e) {
var keyCode = e.getKey(); var keyCode = e.getKey();
var keyCtrl = e.ctrlKey; var keyCtrl = e.ctrlKey;
console.log('GanttButtonController.onWindowKeyDown: code='+keyCode+', ctrl='+keyCtrl); console.log('HourWeeklyController.onWindowKeyDown: code='+keyCode+', ctrl='+keyCtrl);
// cancel hour logging with Esc key // cancel hour logging with Esc key
if (27 == keyCode) { if (27 == keyCode) {
...@@ -140,61 +147,56 @@ Ext.define('PO.tsweekly.HourWeeklyController', { ...@@ -140,61 +147,56 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
// Click into the empty space below the grid entries in order to start creating a new entry // Click into the empty space below the grid entries in order to start creating a new entry
onGridContainerClick: function() { onGridContainerClick: function() {
console.log('GanttButtonController.GridContainerClick'); var me = this;
var buttonStartLogging = Ext.getCmp('buttonStartLogging'); if (me.debug) console.log('HourWeeklyController.GridContainerClick: Starting');
var disabled = buttonStartLogging.disabled;
if (!disabled) {
this.onButtonStartLogging();
}
},
/*
* Start logging the time.
* Before calling this procedure, the user must have selected a single
* leaf in the task tree for logging hours.
*/
onButtonStartLogging: function() {
console.log('GanttButtonController.ButtonStartLogging');
alert('xxx');
if (me.debug) console.log('HourWeeklyController.GridContainerClick: Finished');
}, },
/* /*
* Start logging the time, for entirely manual entries. * Start logging the time, for entirely manual entries.
*/ */
onButtonAddEntry: function() { onButtonAddEntry: function() {
console.log('GanttButtonController.ButtonManualLogging'); var me = this;
if (me.debug) console.log('HourWeeklyController.!!! ButtonManualLogging');
var buttonAddEntry = Ext.getCmp('buttonAddEntry'); // var buttonAddEntry = Ext.getCmp('buttonAddEntry');
var buttonDeleteEntry = Ext.getCmp('buttonDeleteEntry'); // var buttonDeleteEntry = Ext.getCmp('buttonDeleteEntry');
// buttonAddEntry.disable(); // buttonAddEntry.disable();
// buttonDeleteEntry.enable(); // buttonDeleteEntry.enable();
rowEditing.cancelEdit(); me.rowEditing.cancelEdit();
var day = PO.Utilities.dateToPg(new Date()); var day = PO.Utilities.dateToPg(new Date());
var hour = new Ext.create('PO.model.timesheet.Hour', { var hourWeekly = new Ext.create('PO.tsweekly.HourWeekly', {
project_id: null,
user_id: @current_user_id@, user_id: @current_user_id@,
day: day day: day
}); });
hourStore.add(hour); me.hourWeeklyStore.add(hourWeekly);
rowEditing.startEdit(hour, 0); var proxy = me.hourWeeklyStore.getProxy();
hourWeekly.setProxy(proxy);
me.rowEditing.startEdit(hourWeekly, 0);
}, },
onButtonDeleteEntry: function() { onButtonDeleteEntry: function() {
var me = this; var me = this;
console.log('GanttButtonController.ButtonDeleteLogging'); console.log('HourWeeklyController.ButtonDeleteLogging');
var buttonAddEntry = Ext.getCmp('buttonAddEntry'); var buttonAddEntry = Ext.getCmp('buttonAddEntry');
// var buttonDeleteEntry = Ext.getCmp('buttonDeleteEntry'); // var buttonDeleteEntry = Ext.getCmp('buttonDeleteEntry');
buttonAddEntry.enable(); buttonAddEntry.enable();
// buttonDeleteEntry.enable(); // buttonDeleteEntry.enable();
rowEditing.cancelEdit(); me.rowEditing.cancelEdit();
var records = hourGrid.getSelectionModel().getSelection(); var records = hourGrid.getSelectionModel().getSelection();
// Not logging already - enable the "start" button // Not logging already - enable the "start" button
if (1 == records.length) { // Exactly one record enabled if (1 == records.length) { // Exactly one record enabled
var record = records[0]; var record = records[0];
hourStore.remove(record); me.hourWeeklyStore.remove(record);
record.destroy(); record.destroy();
} }
}, },
...@@ -204,15 +206,13 @@ Ext.define('PO.tsweekly.HourWeeklyController', { ...@@ -204,15 +206,13 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
* Skip logging hours when changing the selection. * Skip logging hours when changing the selection.
*/ */
onTreePanelSelectionChange: function(view, records) { onTreePanelSelectionChange: function(view, records) {
if (this.debug) { console.log('GanttButtonController.onTreePanelSelectionChange'); } if (this.debug) { console.log('HourWeeklyController.onTreePanelSelectionChange'); }
var buttonStartLogging = Ext.getCmp('buttonStartLogging');
var buttonAddEntry = Ext.getCmp('buttonAddEntry'); var buttonAddEntry = Ext.getCmp('buttonAddEntry');
// Not logging already - enable the "start" button // Not logging already - enable the "start" button
if (1 == records.length) { // Exactly one record enabled if (1 == records.length) { // Exactly one record enabled
} else { // Zero or two or more records enabled } else { // Zero or two or more records enabled
buttonStartLogging.setDisabled(true);
buttonAddEntry.setDisabled(true); buttonAddEntry.setDisabled(true);
} }
}, },
...@@ -222,7 +222,7 @@ Ext.define('PO.tsweekly.HourWeeklyController', { ...@@ -222,7 +222,7 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
* Enable or disable the "Delete" button * Enable or disable the "Delete" button
*/ */
onGridSelectionChange: function(view, records) { onGridSelectionChange: function(view, records) {
if (this.debug) { console.log('GanttButtonController.onGridSelectionChange'); } if (this.debug) { console.log('HourWeeklyController.onGridSelectionChange'); }
var buttonDeleteEntry = Ext.getCmp('buttonDeleteEntry'); var buttonDeleteEntry = Ext.getCmp('buttonDeleteEntry');
buttonDeleteEntry.setDisabled(1 != records.length); buttonDeleteEntry.setDisabled(1 != records.length);
}, },
...@@ -232,10 +232,10 @@ Ext.define('PO.tsweekly.HourWeeklyController', { ...@@ -232,10 +232,10 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
* Handle various key actions * Handle various key actions
*/ */
onCellKeyDown: function(table, htmlTd, cellIndex, record, htmlTr, rowIndex, e, eOpts) { onCellKeyDown: function(table, htmlTd, cellIndex, record, htmlTr, rowIndex, e, eOpts) {
console.log('GanttButtonController.onCellKeyDown'); console.log('HourWeeklyController.onCellKeyDown');
var keyCode = e.getKey(); var keyCode = e.getKey();
var keyCtrl = e.ctrlKey; var keyCtrl = e.ctrlKey;
console.log('GanttButtonController.onCellKeyDown: code='+keyCode+', ctrl='+keyCtrl); console.log('HourWeeklyController.onCellKeyDown: code='+keyCode+', ctrl='+keyCtrl);
} }
}); });
Ext.define('PO.tsweekly.HourWeeklyProxy', {
extend: 'Ext.data.proxy.Client',
alias: 'proxy.hourWeeklyProxy',
debug: true,
constructor: function(config) {
this.callParent(arguments);
},
/**
* Fake processing function to commit the records, set the current operation
* to successful and call the callback if provided. This function is shared
* by the create, update and destroy methods to perform the bare minimum
* processing required for the proxy to register a result from the action.
*/
updateOperation: function(operation, callback, scope) {
var i = 0,
recs = operation.getRecords(),
len = recs.length;
for (i; i < len; i++) {
recs[i].commit();
}
operation.setCompleted();
operation.setSuccessful();
Ext.callback(callback, scope || this, [operation]);
},
//inherit docs
create: function(operation, callback, scope) {
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.create: Started'); console.log(operation); }
this.updateOperation.apply(this, arguments);
if (me.debug) console.log('HourWeeklyProxy.create: Finished');
},
//inherit docs
read: function(operation, callback, scope) {
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.read: Started'); console.log(operation); }
operation.setStarted();
var data = [
{ data: { name: 'File1', thumbnail: '/piko/desktop/img/my_photos.png', url: '/img/faces.jpg', size: 32000, metadata: { type: 'file', width: 64, height: 64 }},
join: function(store) { this.store = store; },
unjoin: function(store) { this.store = store; }},
// { data: { name: 'File2', thumbnail: '/piko/desktop/img/my_photos.png', url: '/img/faces.jpg', size: 32000, metadata: { type: 'file', width: 64, height: 64 }}, join: function(store) { this.store = store; }},
];
operation.resultSet = Ext.create('Ext.data.ResultSet', {
records: data,
total: data.length,
loaded: true
});
operation.commitRecords(data);
operation.setCompleted();
operation.setSuccessful();
if (typeof callback == 'function') {
callback.call(scope || this, operation);
}
if (me.debug) console.log('HourWeeklyProxy.read: Finished');
},
//inherit docs
update: function(operation, callback, scope) {
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.update: Started'); console.log(operation); }
this.updateOperation.apply(this, arguments);
if (me.debug) console.log('HourWeeklyProxy.update: Finished');
},
//inherit
destroy: function(operation, callback, scope) {
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.destroy: Started'); console.log(operation); }
this.updateOperation.apply(this, arguments);
if (me.debug) console.log('HourWeeklyProxy.destroy: Finished');
},
clear: function() {
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.clear: Started'); console.log(operation); }
this.updateOperation.apply(this, arguments);
if (me.debug) console.log('HourWeeklyProxy.clear: Finished');
}
});
...@@ -5,12 +5,24 @@ ...@@ -5,12 +5,24 @@
// All rights reserved. Please see // All rights reserved. Please see
// https://www.project-open.com/license/ for details. // https://www.project-open.com/license/ for details.
Ext.define('PO.tsweekly.HourWeeklyStore', { Ext.define('PO.tsweekly.HourWeeklyStore', {
extend: 'Ext.data.Store', extend: 'Ext.data.Store',
model: 'PO.tsweekly.HourWeekly', model: 'PO.tsweekly.HourWeekly',
storeId: 'hourWeeklyStore', storeId: 'hourWeeklyStore',
autoDestroy: true, autoDestroy: true,
autoLoad: false, autoLoad: false,
autoSync: false autoSync: false,
proxy: { type: 'hourWeeklyProxy' }
/* data: hourWeeklyStoreJson,
var hourWeeklyStoreJson = {};
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'users'
}
}
*/
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment