From 7254a83bc514a64c05059067bacfe13efaf6284f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jordan=20Aug=C3=A9?= Date: Fri, 11 Jul 2014 10:48:58 +0200 Subject: [PATCH] fixed various issues in scheduler and apply --- manifoldapi/static/js/manifold.js | 62 +++++--- plugins/apply/static/js/apply.js | 7 +- plugins/scheduler2/static/css/scheduler2.css | 7 + plugins/scheduler2/static/js/scheduler2.js | 142 +++++++++++++++---- plugins/scheduler2/templates/scheduler.html | 1 + 5 files changed, 163 insertions(+), 56 deletions(-) diff --git a/manifoldapi/static/js/manifold.js b/manifoldapi/static/js/manifold.js index ea8a6467..57a6c390 100644 --- a/manifoldapi/static/js/manifold.js +++ b/manifoldapi/static/js/manifold.js @@ -345,6 +345,12 @@ function QueryStore() { return query_ext.records.get(record_key); } + this.del_record = function(query_uuid, record_key) + { + var query_ext = this.find_analyzed_query_ext(query_uuid); + return query_ext.records.remove(record_key); + } + this.add_record = function(query_uuid, record, new_state) { var query_ext, key, record_key; @@ -375,8 +381,14 @@ function QueryStore() { } else { record_key = record; } - - manifold.query_store.set_record_state(query_uuid, record_key, STATE_SET, new_state); + + if ((query_ext.query.object == 'lease') && (new_state == STATE_SET_OUT)) { + // Leases that are marked out are in fact leases from other slices + // We need to _remove_ leases that we mark as OUT + manifold.query_store.del_record(query_uuid, record_key); + } else { + manifold.query_store.set_record_state(query_uuid, record_key, STATE_SET, new_state); + } } this.iter_records = function(query_uuid, callback) @@ -1018,25 +1030,16 @@ var manifold = { if (query_ext.set_query_ext) { // We have a domain query // The results are stored in the corresponding set_query - if (query.object == 'lease') { - // temp fix for leases_all - manifold.query_store.set_records(query_ext.set_query_ext.query.query_uuid, records, STATE_SET_IN); - } else { - manifold.query_store.set_records(query_ext.set_query_ext.query.query_uuid, records); - } + manifold.query_store.set_records(query_ext.set_query_ext.query.query_uuid, records); } else if (query_ext.domain_query_ext) { // We have a set query, it is only used to determine which objects are in the set, we should only retrieve the key // Has it a domain query, and has it completed ? - if (query.object == 'lease') { - $.noop(); // slice leases should be included in the results from the domain query lease_all - } else { - $.each(records, function(i, record) { - var key = manifold.metadata.get_key(query.object); - var record_key = manifold.record_get_value(record, key); - manifold.query_store.set_record_state(query.query_uuid, record_key, STATE_SET, STATE_SET_IN); - }); - } + $.each(records, function(i, record) { + var key = manifold.metadata.get_key(query.object); + var record_key = manifold.record_get_value(record, key); + manifold.query_store.set_record_state(query.query_uuid, record_key, STATE_SET, STATE_SET_IN); + }); } else { // We have a normal query @@ -1335,6 +1338,14 @@ case TYPE_LIST_OF_VALUES: data = { state: STATE_SET, key : field, op : new_state, value: added_key } manifold.raise_record_event(query_uuid, FIELD_STATE_CHANGED, data); + + // Inform subquery also + data.key = ''; + manifold.raise_record_event(cur_query_uuid, FIELD_STATE_CHANGED, data); + // XXX Passing no parameters so that they can redraw everything would + // be more efficient but is currently not supported + // XXX We could also need to inform plugins about nodes IN (not pending) that are no more, etc. + // XXX refactor all this when suppressing update_queries, and relying on state instead ! }); $.each(removed_keys, function(i, removed_key) { new_state = (manifold._in_array(removed_key, result_keys, key)) ? STATE_SET_OUT_FAILURE : STATE_SET_OUT_SUCCESS; @@ -1347,6 +1358,10 @@ case TYPE_LIST_OF_VALUES: data = { state: STATE_SET, key : field, op : new_state, value: removed_key } manifold.raise_record_event(query_uuid, FIELD_STATE_CHANGED, data); + + // Inform subquery also + data.key = ''; + manifold.raise_record_event(cur_query_uuid, FIELD_STATE_CHANGED, data); }); break; @@ -1359,6 +1374,7 @@ case TYPE_LIST_OF_VALUES: var query_ext = manifold.query_store.find_query_ext(query.query_uuid); query_ext.query_state = QUERY_STATE_DONE; + // Send DONE message to plugins query.iter_subqueries(function(sq, data, parent_query) { manifold.raise_record_event(sq.query_uuid, DONE); @@ -1549,7 +1565,7 @@ case TYPE_LIST_OF_VALUES: } }, - _enforce_constraints: function(query_ext, record, resource_key, event_type) + _enforce_constraints: function(query_ext, record, record_key, event_type) { var query, data; @@ -1564,14 +1580,14 @@ case TYPE_LIST_OF_VALUES: // XXX Not always a resource var is_reservable = (record.exclusive == true); if (is_reservable) { - var warnings = manifold.query_store.get_record_state(query.query_uuid, resource_key, STATE_WARNINGS); + var warnings = manifold.query_store.get_record_state(query.query_uuid, record_key, STATE_WARNINGS); if (event_type == STATE_SET_ADD) { // We should have a lease_query associated var lease_query = query_ext.parent_query_ext.query.subqueries['lease']; // in options var lease_query_ext = manifold.query_store.find_analyzed_query_ext(lease_query.query_uuid); // Do we have lease records (in) with this resource - var lease_records = $.grep(lease_query_ext.records.entries(), this._grep_active_lease_callback(lease_query, resource_key)); + var lease_records = $.grep(lease_query_ext.records.entries(), this._grep_active_lease_callback(lease_query, record_key)); if (lease_records.length == 0) { // Sets a warning // XXX Need for a better function to manage warnings @@ -1586,7 +1602,7 @@ case TYPE_LIST_OF_VALUES: delete warnings[CONSTRAINT_RESERVABLE_LEASE]; } - manifold.query_store.set_record_state(query.query_uuid, resource_key, STATE_WARNINGS, warnings); + manifold.query_store.set_record_state(query.query_uuid, record_key, STATE_WARNINGS, warnings); } /* This was redundant */ @@ -1595,7 +1611,7 @@ case TYPE_LIST_OF_VALUES: // Signal the change to plugins (even if the constraint does not apply, so that the plugin can display a checkmark) data = { state: STATE_WARNINGS, - key : resource_key, + key : record_key, op : null, value : warnings } @@ -1603,7 +1619,7 @@ case TYPE_LIST_OF_VALUES: break; case 'lease': - var resource_key = record.resource; + var resource_key = record_key.resource; var resource_query = query_ext.parent_query_ext.query.subqueries['resource']; var warnings = manifold.query_store.get_record_state(resource_query.query_uuid, resource_key, STATE_WARNINGS); diff --git a/plugins/apply/static/js/apply.js b/plugins/apply/static/js/apply.js index 676babc6..19730281 100644 --- a/plugins/apply/static/js/apply.js +++ b/plugins/apply/static/js/apply.js @@ -344,11 +344,12 @@ // XXX how do we handle status reset ? // Jordan : I don't understand this. I added this test otherwise we have string = ""..."" double quoted twice. - if (typeof(data.value) !== "string") - data.value = JSON.stringify(data.value); data.selected_resources = this.selected_resources; row = this.find_row(data.value); - newline = [action, data.key, data.value, msg, button]; + if (typeof(data.value) !== "string") + newline = [action, data.key, JSON.stringify(data.value), msg, button]; + else + newline = [action, data.key, data.value, msg, button]; if (!row) { // XXX second parameter refresh = false can improve performance. todo in querytable also this.table.fnAddData(newline); diff --git a/plugins/scheduler2/static/css/scheduler2.css b/plugins/scheduler2/static/css/scheduler2.css index ffbe4f1d..b16eb801 100755 --- a/plugins/scheduler2/static/css/scheduler2.css +++ b/plugins/scheduler2/static/css/scheduler2.css @@ -215,6 +215,13 @@ cursor: not-allowed; } +#scheduler-reservation-table tbody tr td.success { + content: "✓"; +} +#scheduler-reservation-table tbody tr td.failure { + content: "✗"; +} + #scheduler-reservation-table tbody tr td.maintenance { background: url("../img/tools-15.png") no-repeat scroll 50% 50% #EDA428; } diff --git a/plugins/scheduler2/static/js/scheduler2.js b/plugins/scheduler2/static/js/scheduler2.js index 59ef6e69..0150830a 100755 --- a/plugins/scheduler2/static/js/scheduler2.js +++ b/plugins/scheduler2/static/js/scheduler2.js @@ -589,11 +589,9 @@ var SCHEDULER_COLWIDTH = 50; var self = this; var scope = this._get_scope(); - var leases = manifold.query_store.get_records(this.options.query_lease_uuid); - $.each(leases, function(i, lease) { + manifold.query_store.iter_records(this.options.query_lease_uuid, function(lease_key, lease) { - console.log("SET LEASES", new Date(lease.start_time* 1000)); - console.log(" ", new Date(lease.end_time* 1000)); + console.log("SET LEASES", lease.resource, new Date(lease.start_time* 1000), new Date(lease.end_time* 1000)); // XXX We should ensure leases are correctly merged, otherwise our algorithm won't work // Populate leases by resource array: this will help us merging leases later @@ -601,33 +599,8 @@ var SCHEDULER_COLWIDTH = 50; scope._leases_by_resource[lease.resource] = []; scope._leases_by_resource[lease.resource].push(lease); - var resource = self.scope_resources_by_key[lease.resource]; - var day_timestamp = SchedulerDateSelected.getTime() / 1000; + self._set_lease_slots(lease_key, lease); - var id_start = (lease.start_time - day_timestamp) / resource.granularity; - - /* Some leases might be in the past */ - if (id_start < 0) - id_start = 0; - /* Leases in the future: ignore */ - if (id_start >= self._all_slots.length) - return true; // ~ continue - - var id_end = (lease.end_time - day_timestamp) / resource.granularity - 1; - var colspan_lease = resource.granularity / self._granularity; //eg. 3600 / 1800 => 2 cells - if (id_end >= self._all_slots.length / colspan_lease) { - /* Limit the display to the current day */ - id_end = self._all_slots.length / colspan_lease - } - - for (i = id_start; i <= id_end; i++) - // the same slots might be affected multiple times. - // PENDING_IN + PENDING_OUT => IN - // - // RESERVED vs SELECTED ! - // - // PENDING !! - resource.leases[i].status = 'selected'; }); }, @@ -661,8 +634,117 @@ var SCHEDULER_COLWIDTH = 50; on_leases_filter_removed: function(filter) { this._get_scope().$apply(); }, on_leases_filter_clear: function() { this._get_scope().$apply(); }, + on_field_state_changed: function(data) + { + /* + this._set_lease_slots(lease_key, lease); + + switch(data.state) { + case STATE_SET: + switch(data.op) { + case STATE_SET_IN: + case STATE_SET_IN_SUCCESS: + case STATE_SET_OUT_FAILURE: + this.set_checkbox_from_data(data.value, true); + this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_RESET); + break; + case STATE_SET_OUT: + case STATE_SET_OUT_SUCCESS: + case STATE_SET_IN_FAILURE: + this.set_checkbox_from_data(data.value, false); + this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_RESET); + break; + case STATE_SET_IN_PENDING: + this.set_checkbox_from_data(data.key, true); + this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_ADDED); + break; + case STATE_SET_OUT_PENDING: + this.set_checkbox_from_data(data.key, false); + this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_REMOVED); + break; + } + break; + + case STATE_WARNINGS: + this.change_status(data.key, data.value); + break; + } + */ + }, + + /* INTERNAL FUNCTIONS */ + _set_lease_slots: function(lease_key, lease) + { + var resource, lease_status, lease_class; + var day_timestamp, id_start, id_end, colspan_lease; + + resource = this.scope_resources_by_key[lease.resource]; + day_timestamp = SchedulerDateSelected.getTime() / 1000; + id_start = (lease.start_time - day_timestamp) / resource.granularity; + + /* Some leases might be in the past */ + if (id_start < 0) + id_start = 0; + /* Leases in the future: ignore */ + if (id_start >= this._all_slots.length) + return true; // ~ continue + + id_end = (lease.end_time - day_timestamp) / resource.granularity - 1; + colspan_lease = resource.granularity / this._granularity; //eg. 3600 / 1800 => 2 cells + if (id_end >= this._all_slots.length / colspan_lease) { + /* Limit the display to the current day */ + id_end = this._all_slots.length / colspan_lease + } + + for (i = id_start; i <= id_end; i++) { + // the same slots might be affected multiple times. + // PENDING_IN + PENDING_OUT => IN + // + // RESERVED vs SELECTED ! + // + // PENDING !! + lease_status = manifold.query_store.get_record_state(this.options.query_lease_uuid, lease_key, STATE_SET); + switch(lease_status) { + case STATE_SET_IN: + lease_class = 'selected'; // my leases + lease_success = ''; + break; + case STATE_SET_IN_SUCCESS: + lease_class = 'selected'; // my leases + lease_success = 'success'; + case STATE_SET_OUT_FAILURE: + lease_class = 'selected'; // my leases + lease_success = 'failure'; + break; + case STATE_SET_OUT: + lease_class = 'reserved'; // other leases + lease_success = ''; + break; + case STATE_SET_OUT_SUCCESS: + lease_class = 'reserved'; // other leases + lease_success = 'success'; + break; + case STATE_SET_IN_FAILURE: + lease_class = 'reserved'; // other leases + lease_success = 'failure'; + break; + case STATE_SET_IN_PENDING: + lease_class = 'pendingin'; + lease_success = ''; + break; + case STATE_SET_OUT_PENDING: + lease_class = 'pendingout'; + lease_success = ''; + break; + + } + resource.leases[i].status = lease_class; + resource.leases[i].success = lease_success; + } + }, + /* XXX IN TEMPLATE XXX if (SchedulerDataViewData.length == 0) { $("#plugin-scheduler").hide(); diff --git a/plugins/scheduler2/templates/scheduler.html b/plugins/scheduler2/templates/scheduler.html index 6edc88eb..231a1d2a 100755 --- a/plugins/scheduler2/templates/scheduler.html +++ b/plugins/scheduler2/templates/scheduler.html @@ -53,6 +53,7 @@ data-slotid="{[{ lease.id }]}" data-groupid="{[{ lease.groupid }]}" ng-class="{{ 'lease.status' }}" + ng-class="{{ 'lease.success' }}" colspan="{[{resource.granularity / granularity}]}" ng-click="select(from+$index, lease, $parent.resource)"> -- 2.43.0