measurable rating will not be editable if the readonly flag is true
@@ -53,12 +53,13 @@ const initialState = {
function isMeasurableEditable(vm, categoryId) {
- console.log(vm.ratings, vm.measurables);
- const editable = !_.chain(vm.ratings)
- .filter(r => _.filter(vm.measurables, m => m.id === r.measurableId).categoryId === categoryId)
- .first();
- console.log(editable);
- return editable;
+ function getMeasurable(r) {
+ return _.first(_.filter(vm.measurables, m => m.id === r.measurableId));
+ }
+
+ const readOnlyRating = _.first(_.filter(vm.ratings,
+ r => getMeasurable(r).categoryId === categoryId && r.isReadOnly));
+ return _.isEmpty(readOnlyRating);
}
function controller($q, serviceBroker) {
@@ -76,12 +77,8 @@ function controller($q, serviceBroker) {
};
vm.$onInit = () => loadData()
- .then(() => serviceBroker.loadViewData(CORE_API.ApplicationStore.getById, [vm.parentEntityRef.id]))
- .then(r => vm.application = r.data);
- // .then(() => vm.editable=!_.filter(r => r.measurableCategoryId === vm.activeAllocationScheme.measurableCategoryId).isReadOnly)
- // .then(() => vm.editable=isMeasurableEditable(vm))
- // .then(() => console.log(vm.ratings, vm.editable, vm.activeAllocationScheme.measurableCategoryId));
-
+ .then(() => serviceBroker.loadViewData(CORE_API.ApplicationStore.getById, [vm.parentEntityRef.id])
+ .then(r => vm.application = r.data));
// -- INTERACT ---
@@ -118,25 +115,21 @@ function controller($q, serviceBroker) {
vm.onViewRatings = () => {
vm.visibility.editor = false;
loadData(true);
- console.log(vm);
};
vm.onEditRatings = () => {
- console.log('editor', vm.visibility.editor);
vm.visibility.editor = true;
hideAllocationScheme();
};
vm.onTabChange = (tab) => {
hideAllocationScheme();
- console.log('change tab', tab);
serviceBroker
.loadViewData(CORE_API.RatingSchemeStore.findRatingsForEntityAndMeasurableCategory,
[vm.parentEntityRef, tab.category.id])
- .then(r => {
- tab.ratingSchemeItems = r.data;
- }).then(() => vm.editable=isMeasurableEditable(vm, tab.category.id));
+ .then(r => tab.ratingSchemeItems = r.data)
+ .then(() => vm.editable = isMeasurableEditable(vm, tab.category.id));
};
}
