Skip to content

Commit

Permalink
Merge pull request #11096 from archesproject/11042-cbyrd-resource-ins…
Browse files Browse the repository at this point in the history
…tance-lifecycle

Adds resource instance lifecycle #11042
  • Loading branch information
chrabyrd authored Aug 9, 2024
2 parents 397853e + 636a93a commit 9a184f6
Show file tree
Hide file tree
Showing 51 changed files with 2,945 additions and 853 deletions.
2 changes: 2 additions & 0 deletions arches/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class GuardedAdmin(GuardedModelAdmin):
models.Widget,
models.UserProfile,
models.GraphModel,
models.ResourceInstanceLifecycle,
models.ResourceInstanceLifecycleState,
models.SearchComponent,
models.IIIFManifest,
models.GroupMapSettings,
Expand Down
4 changes: 4 additions & 0 deletions arches/app/media/css/arches.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10403,6 +10403,10 @@ a.filter-tools:hover {
height: 100%;
}

.editor-report .resource-report-abstract-container .resource-component-abstract {
height: calc(100vh - 150px);
}

.editor-report .rp-report-section {
border-bottom: none;
padding-bottom: 0;
Expand Down
56 changes: 42 additions & 14 deletions arches/app/media/js/views/components/resource-report-abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ define([
'viewmodels/card',
], function($, _, ko, arches, reportLookup, ReportModel, GraphModel, AlertViewmodel, resourceReportAbstractTemplate) {
var ResourceReportAbstract = function(params) {
var self = this;
var CardViewModel = require('viewmodels/card');
var self = this; // eslint-disable-line @typescript-eslint/no-this-alias
var CardViewModel = require('viewmodels/card'); // eslint-disable-line @typescript-eslint/no-require-imports

this.loading = ko.observable(true);

Expand All @@ -23,38 +23,66 @@ define([
this.configForm = params.configForm;
this.configType = params.configType;

this.graphHasDifferentPublication = ko.observable(params.graph_has_different_publication === "True" ? true : false);
this.graphHasUnpublishedChanges = ko.observable(params.graph_has_unpublished_changes === "True" ? true : false);
this.graphHasDifferentPublication = ko.observable(params.graph_has_different_publication === "True");
this.graphHasUnpublishedChanges = ko.observable(params.graph_has_unpublished_changes === "True");
this.graphHasDifferentPublicationAndUserHasInsufficientPermissions = ko.observable(
params.graph_has_different_publication_and_user_has_insufficient_permissions === "True" ? true : false
params.graph_has_different_publication_and_user_has_insufficient_permissions === "True"
);

const urlSearchParams = new URLSearchParams(window.location.search);
this.userHasBeenRedirected = urlSearchParams.get('redirected');

this.resourceInstanceLifecycleStatePermitsEditing =
params.resource_instance_lifecycle_state_permits_editing === "True";

this.userCanEditResource = params.user_can_edit_resource === "True";

this.template = ko.observable();
this.report = ko.observable();

this.initialize = function() {
var url;
params.cache = params.cache === undefined ? true : params.cache;

if (params.view && self.graphHasDifferentPublication()) {
if (self.graphHasDifferentPublicationAndUserHasInsufficientPermissions()) {
if (params.view) {
if (self.userHasBeenRedirected && !self.resourceInstanceLifecycleStatePermitsEditing) {
params.view.alert(new AlertViewmodel(
'ep-alert-red',
arches.translations.resourceGraphHasDifferentPublicationUserIsNotPermissioned.title,
arches.translations.resourceGraphHasDifferentPublicationUserIsNotPermissioned.text,
'ep-alert-blue',
arches.translations.resourceReportRedirectFromResourceEditorLifecycleState.title,
arches.translations.resourceReportRedirectFromResourceEditorLifecycleState.text,
null,
function() {}
));
}
else {
else if (self.userHasBeenRedirected && !self.userCanEditResource) {
params.view.alert(new AlertViewmodel(
'ep-alert-red',
arches.translations.resourceGraphHasDifferentPublication.title,
arches.translations.resourceGraphHasDifferentPublication.text,
arches.translations.resourceReportRedirectFromResourceEditorNotPermissioned.title,
arches.translations.resourceReportRedirectFromResourceEditorNotPermissioned.text,
null,
function() {}
));
}
else if (self.graphHasDifferentPublication()) {
if (self.graphHasDifferentPublicationAndUserHasInsufficientPermissions()) {
params.view.alert(new AlertViewmodel(
'ep-alert-red',
arches.translations.resourceGraphHasDifferentPublicationUserIsNotPermissioned.title,
arches.translations.resourceGraphHasDifferentPublicationUserIsNotPermissioned.text,
null,
function() {}
));
}
else {
params.view.alert(new AlertViewmodel(
'ep-alert-red',
arches.translations.resourceGraphHasDifferentPublication.title,
arches.translations.resourceGraphHasDifferentPublication.text,
null,
function() {}
));
}
}
}

if (params.report) {
Expand Down Expand Up @@ -121,7 +149,7 @@ define([
const displayName = (() => {
try{
return JSON.parse(responseJson.displayname)?.[arches.activeLanguage]?.value;
} catch (e){
} catch (e){ // eslint-disable-line @typescript-eslint/no-unused-vars
return responseJson.displayname;
}
})();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
define([
'knockout',
'arches',
'views/components/search/base-filter',
'templates/views/components/search/lifecycle-state-filter.htm',
], function(ko, arches, BaseFilter, lifecycleStateFilterTemplate) {
var componentName = 'lifecycle-state-filter';
const viewModel = BaseFilter.extend({
initialize: async function(options) {
options.name = 'Lifecycle State Filter';

this.requiredFilters = ['term-filter'];
BaseFilter.prototype.initialize.call(this, options);

this.lifecycleStates = ko.observableArray();
this.filter = ko.observableArray();

const self = this; // eslint-disable-line @typescript-eslint/no-this-alias

const response = await fetch(arches.urls.api_resource_instance_lifecycle_states);
if (response.ok) {
const data = await response.json();
data.forEach(function(lifecycleState) {
self.lifecycleStates.push(lifecycleState);
});
} else {
console.error('Failed to fetch resource instance list');
}

var filterUpdated = ko.computed(function() {
return JSON.stringify(ko.toJS(this.filter()));
}, this);
filterUpdated.subscribe(function() {
this.updateQuery();
}, this);

this.filters[componentName](this);

if (this.requiredFiltersLoaded() === false) {
this.requireFiltersLoadedSubscription = this.requiredFiltersLoaded.subscribe(function() {
this.restoreState();
self.requireFiltersLoadedSubscription.dispose();
}, this);
} else {
this.restoreState();
}
},

updateQuery: function() {
var queryObj = this.query();
if(this.filter().length > 0){
queryObj[componentName] = ko.toJSON(this.filter);
} else {
delete queryObj[componentName];
}
this.query(queryObj);
},

restoreState: function() {
var query = this.query();
if (componentName in query) {
var lifecycleStateQuery = JSON.parse(query[componentName]);
if (lifecycleStateQuery.length > 0) {
lifecycleStateQuery.forEach(function(type){
type.inverted = ko.observable(!!type.inverted);
this.getFilter('term-filter').addTag(type.name, this.name, type.inverted);
}, this);
this.filter(lifecycleStateQuery);
}
}
},

clear: function() {
this.filter.removeAll();
},

selectLifecycleState: function(item){
this.filter().forEach(function(filterItem){
this.getFilter('term-filter').removeTag(filterItem.name);
}, this);

if (item) {
var inverted = ko.observable(false);
this.getFilter('term-filter').addTag(item.name, this.name, inverted);
this.filter([{id: item.id, name: item.name, inverted: inverted}]);
}
else{
this.clear();
}
}
});

return ko.components.register(componentName, {
viewModel: viewModel,
template: lifecycleStateFilterTemplate,
});
});
10 changes: 6 additions & 4 deletions arches/app/media/js/views/resource/edit-log.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require([
require([ // eslint-disable-line @typescript-eslint/no-require-imports
'jquery',
'underscore',
'knockout',
Expand All @@ -9,15 +9,17 @@ require([
], function($, _, ko, moment, BaseManagerView, data) {
var ResourceEditLogView = BaseManagerView.extend({
initialize: function(options){
var self = this;
const self = this; // eslint-disable-line @typescript-eslint/no-this-alias
var cards = data.cards;
var edits = data.edits;

var editTypeLookup = {
'create': {icon: 'fa fa-chevron-circle-right fa-lg', color: 'bg-mint'},
'tile edit': {icon: 'fa fa-repeat fa-lg', color: 'bg-purple'},
'tile create': {icon: 'fa fa-plus fa-lg', color: 'bg-dark'},
'tile delete': {icon: 'fa fa-minus fa-lg', color: 'bg-danger'},
'delete edit': {icon: 'fa fa-minus fa-lg', color: 'bg-danger'}
'delete edit': {icon: 'fa fa-minus fa-lg', color: 'bg-danger'},
'update_resource_instance_lifecycle_state': {icon: 'fa fa-exclamation fa-lg', color: 'bg-warning'},
};

var handleChildCards = function(card) {
Expand Down Expand Up @@ -59,7 +61,7 @@ require([
}, this);
}
});
return _.map(full_value, function(v,k){return v;});
return _.map(full_value, function(v,k){return v;}); // eslint-disable-line @typescript-eslint/no-unused-vars
};

_.each(edits, function(edit){
Expand Down
34 changes: 31 additions & 3 deletions arches/app/media/js/views/resource/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ define([
if(typeof data.displayname == 'string') {
parsedDisplayName = JSON.parse(data.displayname);
}
} catch(e){
} catch(e){ // eslint-disable-line @typescript-eslint/no-unused-vars
// empty
}

Expand Down Expand Up @@ -168,6 +168,7 @@ define([
userIsCreator: userIsCreator,
showGrid: ko.observable(false),
creator: creator,
resourceInstanceLifecycleState: ko.observable(data.resource_instance_lifecycle_state),
// appliedFunctions: appliedFunctions(),
graph: {
graphid: data.graphid,
Expand Down Expand Up @@ -286,6 +287,33 @@ define([
));
}
},
updateResourceInstanceLifecycleState: function(data) {
$.ajax({
type: "POST",
url: arches.urls.api_resource_instance_lifecycle_state(resourceId()),
data: JSON.stringify(data['id']),
error: function(err) {
vm.alert(new JsonErrorAlertViewModel('ep-alert-red', err.responseJSON));
},
success: function() {
window.location.reload(); // reload is important here, for enforcing a report redirect on an unpermissioned user
}
});
},
onSaveSuccess: function() {
if (!vm.resourceInstanceLifecycleState()) {
$.ajax({
type: "GET",
url: arches.urls.api_resource_instance_lifecycle_state(resourceId()),
error: function(err) {
vm.alert(new JsonErrorAlertViewModel('ep-alert-red', err.responseJSON));
},
success: function(data) {
vm.resourceInstanceLifecycleState(data);
}
});
}
},
viewEditHistory: function() {
if (resourceId()) {
vm.menuActive(false);
Expand Down Expand Up @@ -317,7 +345,7 @@ define([
});

vm.showRelatedResourcesManager = function(){
require(['views/resource/related-resources-manager'], () => {
require(['views/resource/related-resources-manager'], () => { // eslint-disable-line @typescript-eslint/no-require-imports
if (vm.graph.domain_connections == undefined) {
$.ajax({
url: arches.urls.relatable_resources,
Expand Down Expand Up @@ -348,7 +376,7 @@ define([
};

vm.showInstancePermissionsManager = function(){
require(['views/resource/permissions-manager'], () => {
require(['views/resource/permissions-manager'], () => { // eslint-disable-line @typescript-eslint/no-require-imports
if (vm.userIsCreator === true || vm.userIsCreator === null) {
vm.selection('permissions-manager');
}
Expand Down
Loading

0 comments on commit 9a184f6

Please sign in to comment.