Commit 4c87a844 authored by Project Open's avatar Project Open

- WIP for Champ timesheet redesign

parent fb63d69c
......@@ -110,6 +110,7 @@ function launchTimesheetWeeklyLogging(){
editor: {
xtype: 'combo',
queryMode: 'local',
// allowBlank: false,
store: projectStore,
displayField: 'project_name',
valueField: 'project_id',
......@@ -134,21 +135,28 @@ function launchTimesheetWeeklyLogging(){
if (!taskModel) return "";
return taskModel.get('project_name');
},
editor: { xtype: 'pocombotree', store: taskTreeStore, queryMode: 'local', displayField: 'project_name', valueField: 'id'}
editor: {
xtype: 'pocombotree',
store: taskTreeStore,
queryMode: 'local',
// allowBlank: false,
displayField: 'project_name',
valueField: 'id'
}
},
{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_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_2',
{text: "<div align=center>Wed<br>4/1/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_3',
{text: "<div align=center>Thu<br>4/2/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_4',
{text: "<div align=center>Fri<br>4/3/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_5',
{text: "<div align=center>Sat<br>4/4/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_6',
{text: "<div align=center>Sun<br>4/5/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) {
......@@ -244,7 +252,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 hourWeeklyStore = Ext.create('PO.tsweekly.HourWeeklyStore', {hourStore: hourStore}); // Create _after_ hourStore
var projectStore = Ext.create('PO.store.project.ProjectMainStore');
// Use a "store coodinator" in order to launchTimesheetWeeklyLogging() only
......
......@@ -7,10 +7,33 @@ Ext.define('PO.tsweekly.HourWeeklyProxy', {
debug: true,
constructor: function(config) {
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.constructor: Started'); console.log(config); }
this.callParent(arguments);
},
if (!me.hourStore) me.hourStore = Ext.StoreManager.get('hourStore');
me.hourStore.on("add", me.onHourAdd, me);
me.hourStore.on("update", me.onHourUpdate, me);
me.hourStore.on("remove", me.onHourRemove, me);
me.hourStore.on("load", me.onHourLoad, me);
if (me.debug) console.log('HourWeeklyProxy.constructor: Finished');
},
onHourAdd: function(a,b,c,d,e) {
console.log('HourWeeklyProxy.onHourAdd');
},
onHourRemove: function(a,b,c,d,e) {
console.log('HourWeeklyProxy.onHourRemove');
},
onHourUpdate: function(a,b,c,d,e) {
console.log('HourWeeklyProxy.onHourUpdate');
},
onHourLoad: function(a,b,c,d,e) {
console.log('HourWeeklyProxy.onHourLoad');
},
/**
* Fake processing function to commit the records, set the current operation
* to successful and call the callback if provided. This function is shared
......@@ -31,23 +54,88 @@ Ext.define('PO.tsweekly.HourWeeklyProxy', {
Ext.callback(callback, scope || this, [operation]);
},
syncHours: function(records) {
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.syncHours: Started'); console.log(records); }
if (!records) return;
// Create/update hours in the HoursStore
var hourStore = me.hourStore;
// Sync from hourWeeklyStore to HourStore
for (var i = 0; i < records.length; i++) {
var record = records[i];
var weekDate = PO.Utilities.pgToDate(record.get('day'));
var dayOfWeek = weekDate.getDay()-1; if (dayOfWeek < 0) dayOfWeek = dayOfWeek+7;
weekDate.setHours(-24 * dayOfWeek);
var project_id = record.get('project_id')+"";
var user_id = record.get('user_id')+"";
console.log(record);
for (d = 0; d < 7; d++) {
var hours = parseFloat(record.get('hours_'+d));
if (!hours) continue
console.log('HourWeeklyProxy.syncHours: d='+d+', hours='+hours);
// Calculate the date of the day-of-week in PG format
var weekDateDay = new Date(weekDate.getTime());
weekDateDay.setHours(24 * d);
var weekDateDayPg = PO.Utilities.dateToPg(weekDateDay).substring(0,10);
// Check if the im_hours object already exists
var hourFound = null;
hourStore.each(function(hour) {
var hourUser = hour.get('user_id');
if (hourUser !== user_id) return;
var hourDate = hour.get('day').substring(0,10);
if (hourDate !== weekDateDayPg) return;
var hourProjectId = hour.get('project_id');
if (hourProjectId !== project_id) return;
hourFound = hour;
return false; // abort and exit iteration
});
console.log('HourWeeklyProxy.syncHours: d='+d+', found im_hour:'); console.log(hourFound);
if (!hourFound) {
// Not found - we have to create a new entry in the im_hours store
var hourFound = new Ext.create('PO.model.timesheet.Hour', {
project_id: project_id,
user_id: user_id,
day: weekDateDayPg
});
me.hourStore.add(hourFound);
} else {
// Hour found - let's update the logged hours
hourFound.set('hours', hours);
}
me.hourStore.sync();
}
}
if (me.debug) console.log('HourWeeklyProxy.syncHours: Finished');
},
//inherit docs
/**
* A new record has been added to the HourWeeklyStore,
* probably by the user by pressing (+) button.
*/
create: function(operation, callback, scope) {
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.create: Started'); console.log(operation); }
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.create: Started'); console.log(operation); }
this.updateOperation.apply(this, arguments);
this.updateOperation.apply(this, arguments);
me.syncHours(operation.records);
if (me.debug) console.log('HourWeeklyProxy.create: Finished');
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); }
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.read: Started'); console.log(operation); }
operation.setStarted();
var data = [
......@@ -70,38 +158,41 @@ Ext.define('PO.tsweekly.HourWeeklyProxy', {
if (typeof callback == 'function') {
callback.call(scope || this, operation);
}
if (me.debug) console.log('HourWeeklyProxy.read: Finished');
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); }
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.update: Started'); console.log(operation); }
this.updateOperation.apply(this, arguments);
this.updateOperation.apply(this, arguments);
me.syncHours(operation.records);
if (me.debug) console.log('HourWeeklyProxy.update: Finished');
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); }
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.destroy: Started'); console.log(operation); }
this.updateOperation.apply(this, arguments);
this.updateOperation.apply(this, arguments);
me.syncHours(operation.records);
if (me.debug) console.log('HourWeeklyProxy.destroy: Finished');
if (me.debug) console.log('HourWeeklyProxy.destroy: Finished');
},
clear: function() {
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.clear: Started'); console.log(operation); }
var me = this;
if (me.debug) { console.log('HourWeeklyProxy.clear: Started'); console.log(operation); }
this.updateOperation.apply(this, arguments);
this.updateOperation.apply(this, arguments);
me.syncHours(operation.records);
if (me.debug) console.log('HourWeeklyProxy.clear: Finished');
if (me.debug) console.log('HourWeeklyProxy.clear: Finished');
}
});
......
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