Skip to content

Commit

Permalink
[FIX]javascript improve code formatting (OCA#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandip Mangukiya authored and murtuzasaleh committed Mar 16, 2020
1 parent 3969885 commit d4fb66c
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 106 deletions.
1 change: 1 addition & 0 deletions fieldservice/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Contributors
* Steve Campbell <scampbell@opensourceintegrators.com>
* Bhavesh Odedra <bodedra@opensourceintegrators.com>
* Michael Allen <mallen@opensourceintegrators.com>
* Sandip Mangukiya <smangukiya@opensourceintegrators.com>

Other credits
~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions fieldservice/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
* Steve Campbell <scampbell@opensourceintegrators.com>
* Bhavesh Odedra <bodedra@opensourceintegrators.com>
* Michael Allen <mallen@opensourceintegrators.com>
* Sandip Mangukiya <smangukiya@opensourceintegrators.com>
106 changes: 70 additions & 36 deletions fieldservice/static/src/js/fsm_gantt.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
odoo.define('fieldservice.fsm_gantt', function (require) {
"use strict";
'use strict';

var core = require('web.core');
var data = require('web.data');
var time = require('web.time');
var session = require('web.session');
var TimelineRenderer = require('web_timeline.TimelineRenderer');

var _t = core._t;
var _lt = core._lt;
var QWeb = core.qweb;

TimelineRenderer.include({
init: function (parent, state, params) {

/**
* Init Overrite
* Parameters:
* @param {Object} parent
* @param {Object} state
* @param {Array} params
*/
init : function (parent, state, params) {
var self = this;
this._super.apply(this, arguments);
this.modelName = params.model;
Expand All @@ -31,20 +35,27 @@ odoo.define('fieldservice.fsm_gantt', function (require) {
self.res_users = [];
self.res_users_ids = [];

// Find their matching names
// Find their matches
this._rpc({
model: 'fsm.person',
method: 'get_person_information',
args: [[session.uid], {}],
}).then(function (result) {
self.res_users.push(result);
for(var r in result){
self.res_users_ids.push(result[r]['id']);
for (var r in result) {
self.res_users_ids.push(result[r].id);
}
});
},

on_data_loaded_2: function (events, group_bys, adjust_window) {
/**
* On data loaded 2
* Parameters:
* @param {Array} events
* @param {Array} group_bys
* @param {Object} adjust_window
*/
on_data_loaded_2 : function (events, group_bys, adjust_window) {
var self = this;
var data = [];
var groups = [];
Expand All @@ -54,29 +65,35 @@ odoo.define('fieldservice.fsm_gantt', function (require) {
data.push(self.event_data_transform(event));
}
});
var groups = self.split_groups(events, group_bys);
if (group_bys[0]=="person_id"){
groups = self.split_groups(events, group_bys);
if (group_bys[0] === 'person_id') {
var groups_user_ids = [];
for(var g in groups){
groups_user_ids.push(groups[g]['id']);
for (var g in groups) {
groups_user_ids.push(groups[g].id);
}
for(var u in self.res_users_ids){
if(!(self.res_users_ids[u] in groups_user_ids) || self.res_users_ids[u] != -1){
for (var u in self.res_users_ids) {
if (!(self.res_users_ids[u] in groups_user_ids) ||
self.res_users_ids[u] !== -1) {

// Get User Name
var user_name = '-';
for (var n in self.res_users[0]){
if (self.res_users[0][n]['id'] == self.res_users_ids[u]){
user_name = self.res_users[0][n]['name'];
for (var n in self.res_users[0]) {
if (self.res_users[0][n].id ===
self.res_users_ids[u]) {
user_name = self.res_users[0][n].name;
}
}
var is_available=false;
for (var i in groups){
if(groups[i]['id']==self.res_users_ids[u]){
var is_available = false;
for (var i in groups) {
if (groups[i].id === self.res_users_ids[u]) {
is_available = true;
}
}
if(!is_available){
groups.push({id:self.res_users_ids[u], content: _t(user_name)});
if (!is_available) {
groups.push({
id:self.res_users_ids[u],
content: _t(user_name),
});
}
}
}
Expand All @@ -89,29 +106,39 @@ odoo.define('fieldservice.fsm_gantt', function (require) {
this.timeline.fit();
}
},
/* Transform Odoo event object to timeline event object */
event_data_transform: function (evt) {

/**
* Transform Odoo event object to timeline event object
* Parameters:
* @param {Array} evt
* @returns r
*/
event_data_transform : function (evt) {
var self = this;
var date_start = new moment();
var date_stop = null;

var date_delay = evt[this.date_delay] || false,
all_day = this.all_day ? evt[this.all_day] : false;

if (all_day) {
date_start = time.auto_str_to_date(evt[this.date_start].split(' ')[0], 'start');
date_start = time.auto_str_to_date(
evt[this.date_start].split(' ')[0], 'start');
if (this.no_period) {
date_stop = date_start;
} else {
date_stop = this.date_stop ? time.auto_str_to_date(evt[this.date_stop].split(' ')[0], 'stop') : null;
date_stop = this.date_stop
? time.auto_str_to_date(
evt[this.date_stop].split(' ')[0], 'stop') : null;
}
} else {
date_start = time.auto_str_to_date(evt[this.date_start]);
date_stop = this.date_stop ? time.auto_str_to_date(evt[this.date_stop]) : null;
date_stop = this.date_stop
? time.auto_str_to_date(evt[this.date_stop]) : null;
}

if (!date_stop && date_delay) {
date_stop = moment(date_start).add(date_delay, 'hours').toDate();
date_stop =
moment(date_start).add(date_delay, 'hours').toDate();
}

var group = evt[self.last_group_bys[0]];
Expand All @@ -121,14 +148,17 @@ odoo.define('fieldservice.fsm_gantt', function (require) {
group = -1;
}
_.each(self.colors, function (color) {
if (eval("'" + evt[color.field] + "' " + color.opt + " '" + color.value + "'")) {
if (eval('\'' + evt[color.field] +
'\' ' + color.opt + ' \'' + color.value + '\'')) {
self.color = color.color;
}else if (eval("'" + evt[color.field][1] + "' " + color.opt + " '" + color.value + "'")) {
} else if (eval('\'' + evt[color.field][1] +
'\' ' + color.opt + ' \'' + color.value + '\'')) {
self.color = color.color;
}
});

var content = _.isUndefined(evt.__name) ? evt.display_name : evt.__name;
var content = _.isUndefined(evt.__name)
? evt.display_name : evt.__name;
if (this.arch.children.length) {
content = this.render_timeline_item(evt);
}
Expand All @@ -139,9 +169,13 @@ odoo.define('fieldservice.fsm_gantt', function (require) {
'id': evt.id,
'group': group,
'evt': evt,
'style': 'background-color: ' + self.color + ';'
'style': 'background-color: ' + self.color + ';',
};
// Check if the event is instantaneous, if so, display it with a point on the timeline (no 'end')

/**
* Check if the event is instantaneous,
* if so, display it with a point on the timeline (no 'end')
*/
if (date_stop && !moment(date_start).isSame(date_stop)) {
r.end = date_stop;
}
Expand Down
Loading

0 comments on commit d4fb66c

Please sign in to comment.