Skip to content

Commit

Permalink
Merge branch 'develop' into 2023_data_import
Browse files Browse the repository at this point in the history
  • Loading branch information
aviveiros11 committed Jan 31, 2020
2 parents 5314e0a + 1f7e8a5 commit 0ad0d3b
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/settings/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
}

if 'default' in SECRET_KEY:
print("WARNING: SECRET_KEY is defaulted. Makes sure to override SECKET_KEY in local_untracked or env var")
print("WARNING: SECRET_KEY is defaulted. Makes sure to override SECRET_KEY in local_untracked or env var")

if 'SENTRY_RAVEN_DSN' in os.environ:
import raven
Expand Down
60 changes: 50 additions & 10 deletions seed/static/seed/js/controllers/data_quality_admin_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ angular.module('BE.seed.controller.data_quality_admin', [])
'auth_payload',
'labels_payload',
'data_quality_service',
'modified_service',
'organization_service',
'label_service',
'spinner_utility',
Expand All @@ -33,6 +34,7 @@ angular.module('BE.seed.controller.data_quality_admin', [])
auth_payload,
labels_payload,
data_quality_service,
modified_service,
organization_service,
label_service,
spinner_utility,
Expand Down Expand Up @@ -115,13 +117,39 @@ angular.module('BE.seed.controller.data_quality_admin', [])
};
loadRules(data_quality_rules_payload);

$scope.isModified = function() {
return modified_service.isModified();
};
var originalRules = angular.copy(data_quality_rules_payload.rules);
$scope.original = originalRules;
$scope.change_rules = function() {
$scope.setModified();
};
$scope.setModified = function () {
$scope.rules_updated = false;
$scope.rules_reset = false;
$scope.defaults_restored = false;
var cleanRules = angular.copy($scope.ruleGroups);
_.each(originalRules, function (rules, index) {
$scope.rules = rules;
Object.keys(rules).forEach(function (key) {
_.reduce(cleanRules[index][rules[key].field], function (result, value) {
return _.isEqual(value, rules[key]) ? modified_service.setModified() : modified_service.resetModified();
}, []);
});
});
};

// Restores the default rules
$scope.restore_defaults = function () {
spinner_utility.show();
$scope.defaults_restored = false;
$scope.rules_reset = false;
data_quality_service.reset_default_data_quality_rules($scope.org.org_id).then(function (rules) {
loadRules(rules);
$scope.defaults_restored = true;
$scope.rules_updated = false;
modified_service.resetModified();
}, function (data) {
$scope.$emit('app_error', data);
}).finally(function () {
Expand All @@ -131,21 +159,28 @@ angular.module('BE.seed.controller.data_quality_admin', [])

// Reset all rules
$scope.reset_all_rules = function () {
spinner_utility.show();
$scope.rules_reset = false;
data_quality_service.reset_all_data_quality_rules($scope.org.org_id).then(function (rules) {
loadRules(rules);
$scope.rules_reset = true;
}, function (data) {
$scope.$emit('app_error', data);
}).finally(function () {
spinner_utility.hide();
return modified_service.showResetDialog().then(function () {
spinner_utility.show();
$scope.rules_reset = false;
$scope.defaults_restored = false;
$scope.rules_updated = false;
return data_quality_service.reset_all_data_quality_rules($scope.org.org_id).then(function (rules) {
loadRules(rules);
$scope.rules_reset = true;
modified_service.resetModified();
}, function (data) {
$scope.$emit('app_error', data);
}).finally(function () {
spinner_utility.hide();
});
});
};

// Saves the configured rules
$scope.save_settings = function () {
$scope.rules_updated = false;
$scope.defaults_restored = false;
$scope.rules_reset = false;
var rules = {
properties: [],
taxlots: []
Expand Down Expand Up @@ -197,6 +232,7 @@ angular.module('BE.seed.controller.data_quality_admin', [])
data_quality_service.save_data_quality_rules($scope.org.org_id, rules).then(function (rules) {
loadRules(rules);
$scope.rules_updated = true;
modified_service.resetModified();
}).then(function (data) {
$scope.$emit('app_success', data);
}).catch(function (data) {
Expand Down Expand Up @@ -304,6 +340,7 @@ angular.module('BE.seed.controller.data_quality_admin', [])
'new': true,
autofocus: true
});
$scope.change_rules();
};

// create label and assign to that rule
Expand All @@ -329,7 +366,10 @@ angular.module('BE.seed.controller.data_quality_admin', [])

// set rule as deleted.
$scope.delete_rule = function (rule, index) {
if ($scope.ruleGroups[$scope.inventory_type][rule.field].length === 1) delete $scope.ruleGroups[$scope.inventory_type][rule.field];
if ($scope.ruleGroups[$scope.inventory_type][rule.field].length === 1) {
delete $scope.ruleGroups[$scope.inventory_type][rule.field];
$scope.change_rules();
}
else $scope.ruleGroups[$scope.inventory_type][rule.field].splice(index, 1);
};

Expand Down
17 changes: 17 additions & 0 deletions seed/static/seed/js/controllers/reset_modal_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* :copyright (c) 2014 - 2020, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Department of Energy) and contributors. All rights reserved.
* :author
*/
angular.module('BE.seed.controller.reset_modal', [])
.controller('reset_modal_controller', [
'$scope',
'$uibModalInstance',
function ($scope, $uibModalInstance) {
$scope.reset = function () {
$uibModalInstance.close();
};

$scope.cancel = function () {
$uibModalInstance.dismiss();
};
}]);
1 change: 1 addition & 0 deletions seed/static/seed/js/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ angular.module('BE.seed.controllers', [
'BE.seed.controller.profile',
'BE.seed.controller.record_match_merge_link_modal',
'BE.seed.controller.rename_column_modal',
'BE.seed.controller.reset_modal',
'BE.seed.controller.security',
'BE.seed.controller.settings_profile_modal',
'BE.seed.controller.show_populated_columns_modal',
Expand Down
9 changes: 9 additions & 0 deletions seed/static/seed/js/services/modified_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,14 @@ angular.module('BE.seed.service.modified', []).factory('modified_service', [
return modalInstance.result;
};

modified_service.showResetDialog = function () {
var modalInstance = $uibModal.open({
templateUrl: urls.static_url + 'seed/partials/reset_modal.html',
controller: 'reset_modal_controller'
});

return modalInstance.result;
};

return modified_service;
}]);
10 changes: 6 additions & 4 deletions seed/static/seed/partials/data_quality_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2><i class="fa fa-flag"></i> <span translate>Data Quality</span></h2>
<button type="button" class="btn btn-danger" ng-click="reset_all_rules()">{$:: 'Reset All Rules' | translate $}
<i class="fa fa-check" ng-show="rules_reset"></i>
</button>
<button type="button" class="btn btn-primary" ng-click="save_settings()">{$:: 'Save Changes' | translate $}
<button type="button" class="btn btn-primary" ng-click="save_settings()" ng-disabled="!isModified()">{$:: 'Save Changes' | translate $}
<i class="fa fa-check" ng-show="rules_updated"></i>
</button>
</div>
Expand All @@ -34,7 +34,9 @@ <h2><i class="fa fa-flag"></i> <span translate>Data Quality</span></h2>
<div class="section_content_container">
<div class="section_content with_padding" style="margin-bottom:15px;">
<h3 translate>Modifying Data Quality Rules</h3>
<p translate>From the table below, select the rules that you want to: 1) enable/disable within your organization, 2) modify the minimum/maximum values to validate against on file upload, and 3) optionally assign or remove a label if the condition is not met.</p>
<p ng-bind-html-unsafe>From the table below, select the rules that you want to: 1) enable/disable within your organization, 2) modify the minimum/maximum values to validate against on file upload, and 3) optionally assign or remove a label if the condition is not met.<br>
Restore Default Rules: reset only default rules.<br>
Reset All Rules: delete all rules and reinitialize the default set of rules</p>
<button class="btn btn-info btn-sm" style="margin-bottom: 15px;" ng-click="create_new_rule()" translate>Create a new rule</button>
<div class="data-quality-tab-container">
<ul class="nav nav-tabs" style="margin-bottom:1px;">
Expand Down Expand Up @@ -66,7 +68,7 @@ <h3 translate>Modifying Data Quality Rules</h3>
</tr>
</thead>
<tbody ng-repeat="field in sortedRuleGroups()">
<tr ng-repeat="rule in ruleGroups[inventory_type][field]" ng-class="{ 'warning' : rule.new, 'disabled' : !rule.enabled }">
<tr ng-repeat="rule in ruleGroups[inventory_type][field]" ng-class="{ 'warning' : rule.new, 'disabled' : !rule.enabled }" ng-click="change_rules()">
<td class="check is_aligned_center" ng-click="rule.rule_type = 1; rule.enabled = !rule.enabled">
<input type="checkbox" ng-model="rule.enabled" class="no-click">
</td>
Expand Down Expand Up @@ -139,7 +141,7 @@ <h3 translate>Modifying Data Quality Rules</h3>
<button type="button" class="btn btn-danger" ng-click="reset_all_rules()">{$:: 'Reset All Rules' | translate $}
<i class="fa fa-check" ng-show="rules_reset"></i>
</button>
<button type="button" class="btn btn-primary" ng-click="save_settings()">{$:: 'Save Changes' | translate $}
<button type="button" class="btn btn-primary" ng-click="save_settings()" ng-disabled="!isModified()">{$:: 'Save Changes' | translate $}
<i class="fa fa-check" ng-show="rules_updated"></i>
</button>
</div>
Expand Down
8 changes: 8 additions & 0 deletions seed/static/seed/partials/reset_modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="modal-header">
<h3 class="modal-title" translate>Are you sure you want to reset all rules?</h3>
</div>
<div class="modal-body" translate>All rules will be deleted and only default rules will be initiated.</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" ng-click="reset()" autofocus translate>Reset</button>
<button type="button" class="btn btn-warning" ng-click="cancel()" translate>Cancel</button>
</div>
1 change: 1 addition & 0 deletions seed/templates/seed/_scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<script src="{{STATIC_URL}}seed/js/controllers/profile_controller.js"></script>
<script src="{{STATIC_URL}}seed/js/controllers/record_match_merge_link_modal_controller.js"></script>
<script src="{{STATIC_URL}}seed/js/controllers/rename_column_modal_controller.js"></script>
<script src="{{STATIC_URL}}seed/js/controllers/reset_modal_controller.js"></script>
<script src="{{STATIC_URL}}seed/js/controllers/security_controller.js"></script>
<script src="{{STATIC_URL}}seed/js/controllers/settings_profile_modal_controller.js"></script>
<script src="{{STATIC_URL}}seed/js/controllers/show_populated_columns_modal_controller.js"></script>
Expand Down

0 comments on commit 0ad0d3b

Please sign in to comment.