* RECORD STATES (for query_store)
******************************************************************************/
-var STATE_SET = 0;
-var STATE_VALUE = 1;
-var STATE_WARNINGS = 2;
-var STATE_VISIBLE = 3;
+var STATE_SET = 20;
+var STATE_VALUE = 21;
+var STATE_WARNINGS = 22;
+var STATE_VISIBLE = 23;
// ACTIONS
var STATE_SET_CHANGE = 0;
// XXX Need for a better function to manage warnings
var warn = CONSTRAINT_RESERVABLE_LEASE_MSG;
warnings[CONSTRAINT_RESERVABLE_LEASE] = warn;
+
+ manifold.query_store.set_record_state(query.query_uuid, record_key, STATE_WARNINGS, warnings);
+ // 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 : record_key,
+ op : null,
+ value : warnings
+ }
+ manifold.raise_record_event(query.query_uuid, FIELD_STATE_CHANGED, data);
+
} else {
// Lease are defined, delete the warning in case it was set previously
delete warnings[CONSTRAINT_RESERVABLE_LEASE];
// Remove warnings attached to this resource
delete warnings[CONSTRAINT_RESERVABLE_LEASE];
}
-
- manifold.query_store.set_record_state(query.query_uuid, record_key, STATE_WARNINGS, warnings);
}
/* This was redundant */
// manifold.query_store.recount(query.query_uuid);
- // 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 : record_key,
- op : null,
- value : warnings
- }
- manifold.raise_record_event(query.query_uuid, FIELD_STATE_CHANGED, data);
break;
case 'lease':
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);
- if (event_type == STATE_SET_ADD) {
+ if (event_type == STATE_SET_ADD || event_type == STATE_SET_IN_PENDING) {
// A lease is added, it removes the constraint
delete warnings[CONSTRAINT_RESERVABLE_LEASE];
} else {
// XXX Need for a better function to manage warnings
var warn = CONSTRAINT_RESERVABLE_LEASE_MSG;
warnings[CONSTRAINT_RESERVABLE_LEASE] = warn;
+
+ // 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,
+ op : null,
+ value : warnings
+ }
+ manifold.raise_record_event(resource_query.query_uuid, FIELD_STATE_CHANGED, data);
} else {
// Lease are defined, delete the warning in case it was set previously
delete warnings[CONSTRAINT_RESERVABLE_LEASE];
}
-
}
-
+ /* Adding a lease can remove a warning and reduce the unconfigured resources */
manifold.query_store.recount(resource_query.query_uuid);
-
- // 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,
- op : null,
- value : warnings
- }
- manifold.raise_record_event(resource_query.query_uuid, FIELD_STATE_CHANGED, data);
break;
}
query = query_ext.query;
switch(event_type) {
+ case STATUS_REMOVE_WARNING:
+ record = manifold.query_store.get_record(query_uuid, data.value);
+ this._enforce_constraints(query_ext, record, data.value, STATE_SET_ADD);
// XXX At some point, should be renamed to RECORD_STATE_CHANGED
case FIELD_STATE_CHANGED:
class FilterStatusPlugin(Plugin):
- def __init__ (self, query=None, **settings):
+ def __init__ (self, query=None, query_lease=None, **settings):
Plugin.__init__ (self, **settings)
self.query = query
+ self.query_lease = query_lease
+ self.query_lease_uuid = query_lease.query_uuid
+
def template_file (self):
return "filter_status.html"
# query_uuid will pass self.query results to the javascript
# and will be available as "record" in :
# on_new_record: function(record)
- return ['plugin_uuid', 'domid', 'query_uuid']
+ return ['plugin_uuid', 'domid', 'query_uuid', 'query_lease_uuid']
def export_json_settings (self):
return True
op : STATE_SET_ADD,
value: new_lease
}
+ prev_state = manifold.query_store.get_record_state($scope.instance.options.query_uuid, resource_urn, STATE_SET);
manifold.raise_event($scope.instance.options.query_lease_uuid, FIELD_STATE_CHANGED, data);
/* Add to local cache also, unless we listen to events from outside */
op : STATE_SET_ADD,
value: resource_urn
};
- manifold.raise_event($scope.instance.options.query_uuid, FIELD_STATE_CHANGED, data_resource);
+ /* Send the message to the list of resources, depending on the previous state */
+ prev_state = manifold.query_store.get_record_state($scope.instance.options.query_uuid, data_resource.value, STATE_SET);
+ if(jQuery.inArray(prev_state,[STATE_SET_OUT,STATE_SET_OUT_SUCCESS,STATE_SET_OUT_PENDING,STATE_SET_IN_FAILURE])>-1){
+ manifold.raise_event($scope.instance.options.query_uuid, FIELD_STATE_CHANGED, data_resource);
+ }
+ /* Remove the warning on resource as we have added Leases to it */
+ //manifold.raise_event($scope.instance.options.query_uuid, STATUS_REMOVE_WARNING, data_resource);
}
$scope._leases_by_resource[resource_urn].push(new_lease);
op : STATE_SET_REMOVE,
value: other_key
}
+ prev_state = manifold.query_store.get_record_state($scope.instance.options.query_uuid, other.resource, STATE_SET);
manifold.raise_event($scope.instance.options.query_lease_uuid, FIELD_STATE_CHANGED, data);
- /* Remove from local cache also, unless we listen to events from outside */
+ /* Remove Lease from local cache also, unless we listen to events from outside */
$scope._leases_by_resource[other.resource] = $.grep($scope._leases_by_resource[other.resource], function(x) { return x != other; });
/* Last lease removed for this resource -> remove the resource from the list */
if($scope._leases_by_resource.hasOwnProperty(other.resource) && $scope._leases_by_resource[other.resource].length == 0){
op : STATE_SET_REMOVE,
value: other.resource
};
- manifold.raise_event($scope.instance.options.query_uuid, FIELD_STATE_CHANGED, data_resource);
+
+ prev_state = manifold.query_store.get_record_state($scope.instance.options.query_uuid, data_resource.value, STATE_SET);
+ /* Remove Resource from local cache */
+ delete $scope._leases_by_resource[data_resource.value]
+ /* Send the message to the list of resources, depending on the previous state */
+ if(jQuery.inArray(prev_state,[STATE_SET_IN,STATE_SET_IN_SUCCESS,STATE_SET_IN_PENDING,STATE_SET_OUT_FAILURE])>-1){
+ manifold.raise_event($scope.instance.options.query_uuid, FIELD_STATE_CHANGED, data_resource);
+ //manifold.raise_event($scope.instance.options.query_uuid, STATUS_REMOVE_WARNING, data_resource);
+ }
}
}
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)
+ on_resources_field_state_changed: function(data)
{
- /*
- this._set_lease_slots(lease_key, lease);
-
+ console.log('on_resources_field_state_changed');
+ console.log(data);
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);
+ //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);
+ // A resource has been removed
+ console.log(this._get_scope()._leases_by_resource);
+ s = this._get_scope();
+ // loop over the list of leases by resource cached
+ $.each(this._get_scope()._leases_by_resource, function(k,v){
+ // if the resource removed is in the list
+ // we need to remove all the leases corresponding to that resoruce
+ if(k == data.value){
+ console.log(k,v);
+ // loop each lease should be removed
+ $.each(v, function(i,lease){
+ console.log(i,lease);
+ s._remove_lease(lease);
+ });
+ }
+ });
break;
+ /*
case STATE_SET_IN_PENDING:
this.set_checkbox_from_data(data.key, true);
this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_ADDED);
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;
+ */
}
- */
},