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([
'PO.store.timesheet.TaskTreeStore',
'PO.tsweekly.HourWeeklyController',
'PO.tsweekly.HourWeekly',
'PO.tsweekly.HourWeeklyProxy',
'PO.tsweekly.HourWeeklyStore',
'PO.view.field.POComboTree'
]);
......@@ -40,6 +41,7 @@ function launchTimesheetWeeklyLogging(){
// -----------------------------------------------------------------------
// Stores
var hourStore = Ext.StoreManager.get('hourStore');
var hourWeeklyStore = Ext.StoreManager.get('hourWeeklyStore');
var taskTreeStore = Ext.StoreManager.get('taskTreeStore');
var projectStore = Ext.StoreManager.get('projectMainStore');
......@@ -75,7 +77,7 @@ function launchTimesheetWeeklyLogging(){
};
var hourGrid = Ext.create('Ext.grid.Panel', {
store: hourStore,
store: hourWeeklyStore,
layout: 'fit',
region: 'center',
columnLines: true,
......@@ -134,26 +136,30 @@ function launchTimesheetWeeklyLogging(){
},
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},
{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},
{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},
{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},
{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},
{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},
{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},
{ text: "Sum", width: 65, dataIndex: 'note', align: "center",
renderer: function(value, metaData, record, rowIndex, colIndex, store, view) {
var hoursString = record.get('hours');
var hoursFloat = parseFloat(hoursString)
if ("number" == typeof(hoursFloat)) return Math.round(700.0 * hoursFloat) / 100.0;
return "";
var sum = 0.0;
for (var i = 0; i < 7; i++) {
var hoursString = record.get('hours_'+i);
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) {
var sum = 0;
......@@ -208,6 +214,8 @@ function launchTimesheetWeeklyLogging(){
var hourController = Ext.create('PO.tsweekly.HourWeeklyController', {
'hourButtonPanel': hourButtonPanel,
'taskTreeStore': taskTreeStore,
'rowEditing': rowEditing,
'hourWeeklyStore': hourWeeklyStore,
'hourGrid': hourGrid
});
hourController.init(this).onLaunch(this);
......@@ -236,6 +244,7 @@ Ext.onReady(function() {
var debug = PO.Utilities.getDebug('default');
var taskTreeStore = Ext.create('PO.store.timesheet.TaskTreeStore');
var hourStore = Ext.create('PO.store.timesheet.HourStore');
var hourWeeklyStore = Ext.create('PO.tsweekly.HourWeeklyStore');
var projectStore = Ext.create('PO.store.project.ProjectMainStore');
// Use a "store coodinator" in order to launchTimesheetWeeklyLogging() only
......
Ext.define('PO.tsweekly.HourWeekly', {
extend: 'Ext.data.Model',
fields: [
......@@ -15,6 +16,15 @@ Ext.define('PO.tsweekly.HourWeekly', {
'hours_4', // How many hours were logged?
'hours_5', // 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', {
hourController: null,
hourGrid: null,
taskTreeStore: null,
rowEditing: null,
hourWeeklyStore: null,
// Setup the various listeners to receive events here
init: function() {
var me = this;
if (me.debug) { console.log('PO.tsweekly.HourWeeklyController: init'); }
if (me.debug) { console.log('PO.tsweekly.HourWeeklyController.init: Starting'); }
this.control({
'#buttonAddEntry': { click: this.onButtonAddEntry },
......@@ -29,12 +31,13 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
// Trying to crate a "change" event from the Project combo,
// 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.
// 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);
if (me.debug) { console.log('PO.tsweekly.HourWeeklyController.init: Finished'); }
return this;
},
......@@ -70,10 +73,12 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
* fills in the end_time.
*/
onGridBeforeEdit: function(editor, context, eOpts) {
console.log('GanttButtonController.onGridBeforeEdit');
var me = this;
if (me.debug) console.log('HourWeeklyController.onGridBeforeEdit: Starting');
// console.log(context.record);
// Return true to indicate to the editor that it's OK to edit
if (me.debug) console.log('HourWeeklyController.onGridBeforeEdit: Finished');
return true;
},
......@@ -81,7 +86,8 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
* Gets called after finishing an edit using the "Update" button
*/
onGridEdit: function(editor, context) {
console.log('GanttButtonController.onGridEdit');
var me = this;
if (me.debug) console.log('HourWeeklyController.onGridEdit: Starting');
var rec = context.record;
var interval_date = rec.get('interval_date');
......@@ -123,13 +129,14 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
rec.save();
rec.commit();
if (me.debug) console.log('HourWeeklyController.onGridEdit: Finished');
},
// Esc (Escape) button pressed somewhere in the application window
onWindowKeyDown: function(e) {
var keyCode = e.getKey();
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
if (27 == keyCode) {
......@@ -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
onGridContainerClick: function() {
console.log('GanttButtonController.GridContainerClick');
var buttonStartLogging = Ext.getCmp('buttonStartLogging');
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');
var me = this;
if (me.debug) console.log('HourWeeklyController.GridContainerClick: Starting');
alert('xxx');
if (me.debug) console.log('HourWeeklyController.GridContainerClick: Finished');
},
/*
* Start logging the time, for entirely manual entries.
*/
onButtonAddEntry: function() {
console.log('GanttButtonController.ButtonManualLogging');
var me = this;
if (me.debug) console.log('HourWeeklyController.!!! ButtonManualLogging');
var buttonAddEntry = Ext.getCmp('buttonAddEntry');
var buttonDeleteEntry = Ext.getCmp('buttonDeleteEntry');
// var buttonAddEntry = Ext.getCmp('buttonAddEntry');
// var buttonDeleteEntry = Ext.getCmp('buttonDeleteEntry');
// buttonAddEntry.disable();
// buttonDeleteEntry.enable();
rowEditing.cancelEdit();
me.rowEditing.cancelEdit();
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@,
day: day
});
hourStore.add(hour);
rowEditing.startEdit(hour, 0);
me.hourWeeklyStore.add(hourWeekly);
var proxy = me.hourWeeklyStore.getProxy();
hourWeekly.setProxy(proxy);
me.rowEditing.startEdit(hourWeekly, 0);
},
onButtonDeleteEntry: function() {
var me = this;
console.log('GanttButtonController.ButtonDeleteLogging');
console.log('HourWeeklyController.ButtonDeleteLogging');
var buttonAddEntry = Ext.getCmp('buttonAddEntry');
// var buttonDeleteEntry = Ext.getCmp('buttonDeleteEntry');
buttonAddEntry.enable();
// buttonDeleteEntry.enable();
rowEditing.cancelEdit();
me.rowEditing.cancelEdit();
var records = hourGrid.getSelectionModel().getSelection();
// Not logging already - enable the "start" button
if (1 == records.length) { // Exactly one record enabled
var record = records[0];
hourStore.remove(record);
me.hourWeeklyStore.remove(record);
record.destroy();
}
},
......@@ -204,15 +206,13 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
* Skip logging hours when changing the selection.
*/
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');
// Not logging already - enable the "start" button
if (1 == records.length) { // Exactly one record enabled
} else { // Zero or two or more records enabled
buttonStartLogging.setDisabled(true);
buttonAddEntry.setDisabled(true);
}
},
......@@ -222,7 +222,7 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
* Enable or disable the "Delete" button
*/
onGridSelectionChange: function(view, records) {
if (this.debug) { console.log('GanttButtonController.onGridSelectionChange'); }
if (this.debug) { console.log('HourWeeklyController.onGridSelectionChange'); }
var buttonDeleteEntry = Ext.getCmp('buttonDeleteEntry');
buttonDeleteEntry.setDisabled(1 != records.length);
},
......@@ -232,10 +232,10 @@ Ext.define('PO.tsweekly.HourWeeklyController', {
* Handle various key actions
*/
onCellKeyDown: function(table, htmlTd, cellIndex, record, htmlTr, rowIndex, e, eOpts) {
console.log('GanttButtonController.onCellKeyDown');
console.log('HourWeeklyController.onCellKeyDown');
var keyCode = e.getKey();
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 @@
// All rights reserved. Please see
// https://www.project-open.com/license/ for details.
Ext.define('PO.tsweekly.HourWeeklyStore', {
extend: 'Ext.data.Store',
model: 'PO.tsweekly.HourWeekly',
storeId: 'hourWeeklyStore',
autoDestroy: true,
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