diff --git a/arches/app/media/js/models/card.js b/arches/app/media/js/models/card.js index 1056c132fcc..06e02a7c23e 100644 --- a/arches/app/media/js/models/card.js +++ b/arches/app/media/js/models/card.js @@ -47,7 +47,6 @@ define([ this.disabled = ko.observable(); this.component_id = ko.observable(); this.constraints = ko.observableArray(); - this.uniqueConstraints = ko.observableArray(); this.set('cards', this.cards); this.set('nodes', this.nodes); @@ -114,13 +113,31 @@ define([ this._card = ko.observable('{}'); this.dirty = ko.computed(function() { - return JSON.stringify(_.extend(JSON.parse(self._card()), self.toJSON())) !== self._card(); + return JSON.stringify( + _.extend( + JSON.parse(self._card()), + self.toJSON()) + ) !== self._card(); }); this.isContainer = ko.computed(function() { return !!self.get('cards')().length; }); + this.setConstraints = function(arr) { + var self = this; + arr.forEach(function(constraint){ + var constraintViewModel = new CardConstraintsViewModel({ + constraint: koMapping.fromJS(constraint), + widgets: self.widgets() + }); + constraintViewModel.constraint.nodes.subscribe(function(){ + self.toJSON(); + }, self); + self.constraints.push(constraintViewModel); + }); + }; + this.sourceData = attributes; this.parse(attributes); this.parseNodes.call(this, attributes); @@ -145,37 +162,6 @@ define([ this.parseNodes(attributes); }, this); - this.updateConstraints = function(){ - var self = this; - return function(){ - var updatedConstraints = self.uniqueConstraints().map(function(c){ - return { - nodeIds: ko.unwrap(c.nodeIds), - uniquetoallinstances: ko.unwrap(c.uniqueToAllInstances), - constraintid: c.constraintid, - cardid: c.cardid - }; - }); - self.constraints(updatedConstraints); - self.set('constraints', updatedConstraints); - self.constraints.valueHasMutated(); - }; - }; - - this.setConstraints = function(arr) { - var self = this; - self.uniqueConstraints.removeAll(); - arr.forEach(function(constraint){ - constraint.widgets = self.widgets(); - var constraintViewModel = new CardConstraintsViewModel(constraint); - constraintViewModel.nodeIds.subscribe(self.updateConstraints()); - constraintViewModel.uniqueToAllInstances.subscribe(self.updateConstraints()); - self.uniqueConstraints.push(constraintViewModel); - }); - }; - - this.setConstraints(this.constraints()); - this.disposables.push(componentIdSubscription); this.disposables.push(cardSubscription); this.disposables.push(widgetSubscription); @@ -198,6 +184,8 @@ define([ */ parse: function(attributes) { var self = this; + // console.log(attributes.data.constraints[0].nodes) + // console.log(attributes.data.constraints[0].nodes) this._attributes = attributes; _.each(attributes.data, function(value, key) { @@ -238,7 +226,13 @@ define([ this.get(key)(value); break; case 'constraints': - this.setConstraints ? this.setConstraints(value) : this.get(key)(value); + if (this.constraints().length === 0) { + this.setConstraints(value); + } else { + this.constraints().forEach(function(constraint, i){ + constraint.update(value[i]); + }); + } break; case 'name': case 'nodegroup_id': @@ -320,7 +314,6 @@ define([ widget.label(originalWidgetData.label); widget.widget_id(originalWidgetData.widget_id); } - // this.setConstraints(this._attributes.data.constraints); }, this); this.parse(this._attributes); }, @@ -333,7 +326,12 @@ define([ key !== 'widgets' && key !== 'datatypes' && key !== 'data' && key !== 'helpactive' && key !== 'config') { if (ko.isObservable(this.attributes[key])) { - if (key === 'cards') { + if (key === 'constraints') { + ret[key] = []; + this.attributes[key]().forEach(function(constraint) { + ret[key].push(constraint.toJSON()); + }, this); + } else if (key === 'cards') { ret[key] = []; this.attributes[key]().forEach(function(card) { ret[key].push(card.toJSON()); diff --git a/arches/app/media/js/viewmodels/card-constraints.js b/arches/app/media/js/viewmodels/card-constraints.js index 36286dd9cbf..d6cbbfa55a6 100644 --- a/arches/app/media/js/viewmodels/card-constraints.js +++ b/arches/app/media/js/viewmodels/card-constraints.js @@ -1,26 +1,31 @@ define([ 'knockout', -], function(ko) { + 'knockout-mapping' +], function(ko, koMapping) { var ConstraintViewModel = function(params) { - - this.uniqueToAllInstances = ko.observable(params.uniquetoallinstances || false); this.widgets = params.widgets || []; - this.nodeIds = ko.observableArray(params.nodes); - this.cardid = params.card_id; - this.constraintid = params.constraintid; + this.constraint = params.constraint; this.getSelect2ConstraintConfig = function(placeholder){ var nodeOptions = this.widgets.map(function(c){return {text: c.label(), id: c.node.nodeid};}); return { clickBubble: true, disabled: false, data: {results: nodeOptions}, - value: this.nodeIds, + value: this.constraint.nodes, multiple: params.multiple || true, closeOnSelect: false, placeholder: placeholder || "Select Widgets", allowClear: true }; }; + this.update = function(val){ + this.constraint.nodes(val.nodes); + this.constraint.constraintid(val.constraintid); + this.constraint.uniquetoallinstances(val.uniquetoallinstances); + }; + this.toJSON = function(){ + return koMapping.toJS(this.constraint); + }; }; diff --git a/arches/app/media/js/views/graph/graph-designer/card-tree.js b/arches/app/media/js/views/graph/graph-designer/card-tree.js index 4e1c417548e..bcf8577ce19 100644 --- a/arches/app/media/js/views/graph/graph-designer/card-tree.js +++ b/arches/app/media/js/views/graph/graph-designer/card-tree.js @@ -36,7 +36,7 @@ define([ if (cardConstraints.length === 0) { cardConstraints.push({ uniquetoallinstances: false, - nodeIds:[], + nodes:[], cardid: undefined, constraintid: undefined }); diff --git a/arches/app/models/card.py b/arches/app/models/card.py index 90572ccb330..374468f2104 100644 --- a/arches/app/models/card.py +++ b/arches/app/models/card.py @@ -45,7 +45,7 @@ def add_nodeconstraints(nodeids, constraint_model): for constraint in constraints: constraintid = constraint.get('constraintid', None) unique_to_all = constraint.get('uniquetoallinstances', False) - nodeids = constraint.get('nodeIds', []) + nodeids = constraint.get('nodes', []) if constraintid is None: constraint_model = models.ConstraintModel() constraint_model.card = self diff --git a/arches/app/templates/views/graph/graph-designer/card-configuration.htm b/arches/app/templates/views/graph/graph-designer/card-configuration.htm index d8a21b35ce9..cfa20f65f03 100644 --- a/arches/app/templates/views/graph/graph-designer/card-configuration.htm +++ b/arches/app/templates/views/graph/graph-designer/card-configuration.htm @@ -117,15 +117,15 @@
- -
+ +
-
+
diff --git a/arches/app/views/graph.py b/arches/app/views/graph.py index b6f7dcb7ac3..9364c825653 100644 --- a/arches/app/views/graph.py +++ b/arches/app/views/graph.py @@ -503,7 +503,6 @@ def post(self, request, cardid=None): card = models.CardModel.objects.get(pk=card_data['id']) card.sortorder = card_data['sortorder'] card.save() - return JSONResponse(data['cards']) return HttpResponseNotFound() diff --git a/arches/management/commands/packages.py b/arches/management/commands/packages.py index ca285295ee3..b9ef46acfd0 100644 --- a/arches/management/commands/packages.py +++ b/arches/management/commands/packages.py @@ -588,6 +588,8 @@ def load_apps(package_dir): try: app_name = os.path.basename(app) management.call_command('startapp', '--template', app, app_name) + management.call_command('makemigrations', app_name, interactive=False) + management.call_command('migrate', new_name, interactive=False) except CommandError as e: print e @@ -627,37 +629,39 @@ def handle_source(source): if setup_db.lower() in ('t', 'true', 'y', 'yes'): self.setup_db(settings.PACKAGE_NAME) - print 'loading package_settings.py' + print('loading package_settings.py') load_package_settings(package_location) - print 'loading preliminary sql' + print('loading preliminary sql') load_preliminary_sql(package_location) - print 'loading system settings' + print('loading system settings') load_system_settings(package_location) - print 'loading widgets' + print('loading widgets') load_widgets(package_location) - print 'loading card components' + print('loading card components') load_card_components(package_location) - print 'loading plugins' + print('loading plugins') load_plugins(package_location) - print 'loading reports' + print('loading reports') load_reports(package_location) - print 'loading functions' + print('loading functions') load_functions(package_location) - print 'loading datatypes' + print('loading datatypes') load_datatypes(package_location) - print 'loading concepts' + print('loading concepts') load_concepts(package_location, overwrite_concepts, stage_concepts) - print 'loading resource models and branches' + print('loading resource models and branches') load_graphs(package_location) - print 'loading resource to resource constraints' + print('loading resource to resource constraints') load_resource_to_resource_constraints(package_location) - print 'loading map layers' + print('loading map layers') load_map_layers(package_location) - print 'loading business data - resource instances and relationships' + print('loading business data - resource instances and relationships') load_business_data(package_location) - print 'loading resource views' + print('loading resource views') load_resource_views(package_location) - print 'loading package css' + print('loading package css') + print('loading apps') + load_apps(package_location) root = settings.APP_ROOT if settings.APP_ROOT is not None else os.path.join(settings.ROOT_DIR, 'app') css_source = os.path.join(package_location, 'extensions', 'css') if os.path.exists(css_source): @@ -667,8 +671,6 @@ def handle_source(source): css_files = glob.glob(os.path.join(css_source, '*.css')) for css_file in css_files: shutil.copy(css_file, css_dest) - load_apps(package_location) - def update_project_templates(self): """