-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11096 from archesproject/11042-cbyrd-resource-ins…
…tance-lifecycle Adds resource instance lifecycle #11042
- Loading branch information
Showing
51 changed files
with
2,945 additions
and
853 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
arches/app/media/js/views/components/search/lifecycle-state-filter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.