Skip to content

Commit

Permalink
Merge pull request #6691 from davidwatkins73/waltz-6687-ci-table
Browse files Browse the repository at this point in the history
Change Initiatives: incomplete assessments filters
  • Loading branch information
jessica-woodland-scott-db authored Aug 4, 2023
2 parents 83c0311 + 3d3821e commit c0a24cf
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.finos.waltz.model.change_initiative;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.finos.waltz.model.assessment_definition.AssessmentDefinition;
import org.finos.waltz.model.assessment_rating.AssessmentRating;
import org.finos.waltz.model.rating.RatingSchemeItem;
import org.immutables.value.Value;

import java.util.Set;

@Value.Immutable
@JsonSerialize(as=ImmutableChangeInitiativeView.class)
public abstract class ChangeInitiativeView {

public abstract Set<ChangeInitiative> changeInitiatives();
public abstract Set<AssessmentDefinition> assessmentDefinitions();
public abstract Set<RatingSchemeItem> ratingSchemeItems();
public abstract Set<AssessmentRating> ratings();

}
45 changes: 1 addition & 44 deletions waltz-ng/client/assessments/assessment-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
*/
import _ from "lodash";
import { indexRatingSchemes } from "../ratings/rating-utils";
import { nest } from "d3-collection";
import { grey } from "../common/colors";
import { refToString } from "../common/entity-utils";
import {CORE_API} from "../common/services/core-api-utils";
import {resolveResponses} from "../common/promise-utils";
Expand Down Expand Up @@ -70,48 +68,6 @@ export function mkEnrichedAssessmentDefinitions(definitions = [],
}


export function mkAssessmentSummaries(definitions = [], schemes = [], ratings = [], total = 0) {
const indexedRatingSchemes = indexRatingSchemes(schemes);
const definitionsById = _.keyBy(definitions, d => d.id);

const nestedRatings = nest()
.key(d => d.assessmentDefinitionId)
.key(d => d.ratingId)
.rollup(xs => xs.length)
.entries(ratings);

return _
.chain(nestedRatings)
.map(d => {
const definition = definitionsById[Number(d.key)];
const assignedTotal = _.sumBy(d.values, v => v.value);
const values = _
.chain(d.values)
.map(v => {
const propPath = [definition.ratingSchemeId, "ratingsById", v.key];
const rating = _.get(indexedRatingSchemes, propPath);
return Object.assign({}, v, { rating, count: v.value });
})
.concat([{
key: "z",
rating: {
id: -1,
name: "Not Provided",
color: grey
},
count: _.max([0, total - assignedTotal])
}])
.filter(d => d.count > 0)
.value();

const extension = { definition, values };
return Object.assign({}, d , extension);
})
.orderBy(d => d.definition.name)
.value();
}


/**
* Given a list of entities, a list of assessment ratings and a desired
* rating will filter the list of entities accordingly
Expand Down Expand Up @@ -154,6 +110,7 @@ export function filterByAssessmentRating(entities = [],
* @param $q
* @param serviceBroker
* @param kind
* @param options
* @param primaryOnly
* @returns {*}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@
~ See the License for the specific
~
-->
<style>
.wcis-inactive-ci {
color: #999;
font-style: italic;
}

<div>
.wcis-inactive-ci a {
color: #777;
font-style: italic;
}
</style>

<div>
<waltz-section-actions>
<button class="btn btn-xs waltz-btn-transparent"
ng-click="$ctrl.visibility.sourcesOverlay = ! $ctrl.visibility.sourcesOverlay">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@

import _ from "lodash";

import { CORE_API } from "../../../common/services/core-api-utils";
import { initialiseData } from "../../../common";
import { mkSelectionOptions } from "../../../common/selector-utils";
import {CORE_API} from "../../../common/services/core-api-utils";
import {initialiseData} from "../../../common";

import template from "./change-initiative-section.html";
import { changeInitiative } from "../../../common/services/enums/change-initiative";
import { getEnumName } from "../../../common/services/enums";
import {changeInitiative} from "../../../common/services/enums/change-initiative";
import {getEnumName} from "../../../common/services/enums";
import indexByKeyForType from "../../../enum-value/enum-value-utilities";
import {isSameParentEntityRef} from "../../../common/entity-utils";
import { fakeInitiative, fakeProgramme } from "../../change-initiative-utils";
import { filterByAssessmentRating, mkAssessmentSummaries } from "../../../assessments/assessment-utils";
import {fakeInitiative, fakeProgramme} from "../../change-initiative-utils";
import {filterByAssessmentRating} from "../../../assessments/assessment-utils";
import {nest} from "d3-collection";
import {grey} from "../../../common/colors";

const bindings = {
parentEntityRef: "<",
Expand Down Expand Up @@ -67,19 +68,34 @@ const initialState = {
},
filterHelpText: "Select an assessment category to filter the change initiatives",
gridOptions: {
columnDefs: [
{ width: "15%", field: "kind", name: "Kind" },
mkRefCol("initiative"),
mkRefCol("programme"),
mkRefCol("project"),
{ width: "25%", field: "name", name: "Name" },
{ width: "15%", field: "lifecyclePhase", name: "Phase" }
],
columnDefs: _.map(
[
{ width: "15%", field: "kind", name: "Kind" },
mkRefCol("initiative"),
mkRefCol("programme"),
mkRefCol("project"),
{ width: "25%", field: "name", name: "Name" },
{ width: "15%", field: "lifecyclePhase", name: "Phase" }
],
enrichWithInactiveStyling),
data: []
}
};


function calcCellClass(grid, row, col, rowRenderIndex, colRenderIndex) {
return row.entity.lifecyclePhase === "Retired"
? "wcis-inactive-ci"
: "";
}


function enrichWithInactiveStyling(col) {
return Object.assign(
{},
col,
{ cellClass: calcCellClass });}

function determineHierarchy(cisById = {}, ci) {
const none = null;

Expand Down Expand Up @@ -147,24 +163,76 @@ function mkTableData(changeInitiatives = [], lifecycleNamesByKey = {}) {
kind: changeKind
}
})
.orderBy(d => ["initiative.name", "programme.name", "project.name", "name"])
.orderBy(d => ["initiative.externalId", "programme.externalId", "project.externalId", "name"])
.value();
}


function mkAssessmentSummaries(definitions = [], schemeItems = [], ratings = [], total = 0) {
const indexedRatingSchemes = indexRatingSchemeItems(schemeItems);
const definitionsById = _.keyBy(definitions, d => d.id);

const nestedRatings = nest()
.key(d => d.assessmentDefinitionId)
.key(d => d.ratingId)
.rollup(xs => xs.length)
.entries(ratings);

return _
.chain(nestedRatings)
.map(d => {
const definition = definitionsById[Number(d.key)];
const assignedTotal = _.sumBy(d.values, v => v.value);
const values = _
.chain(d.values)
.map(v => {
const propPath = [definition.ratingSchemeId, "ratingsById", v.key];
const rating = _.get(indexedRatingSchemes, propPath);
return Object.assign({}, v, { rating, count: v.value });
})
.concat([{
key: "z",
rating: {
id: -1,
name: "Not Provided",
color: grey
},
count: _.max([0, total - assignedTotal])
}])
.filter(d => d.count > 0)
.value();

const extension = { definition, values };
return Object.assign({}, d , extension);
})
.orderBy(d => d.definition.name)
.value();
}

/**
* Given a flat list of rating schemes returns them indexed by their ids. Also each scheme has
* an additional maps giving 'ratingsByCode' and 'ratingsById' .
* @param schemes
*/
function indexRatingSchemeItems(schemeItems = []) {
return _
.chain(schemeItems)
.groupBy(d => d.ratingSchemeId)
.map((v,k) => Object.assign({}, {
id: k,
ratingsByCode: _.keyBy(v, d => d.rating),
ratingsById: _.keyBy(v, d => d.id),
}))
.keyBy(d => d.id)
.value();
}


function controller($q, serviceBroker) {
const vm = initialiseData(this, initialState);

function init() {
const schemesPromise = serviceBroker
.loadAppData(CORE_API.RatingSchemeStore.findAll)
.then(r => vm.ratingSchemes = r.data);

const assessmentDefinitionsPromise = serviceBroker
.loadAppData(
CORE_API.AssessmentDefinitionStore.findByKind,
[ "CHANGE_INITIATIVE" ])
.then(r => vm.assessmentDefinitions = r.data);
vm.$onChanges = (changes) => {
const sameParent = isSameParentEntityRef(changes);

const enumPromise = serviceBroker
.loadAppData(CORE_API.EnumValueStore.findAll)
Expand All @@ -174,35 +242,25 @@ function controller($q, serviceBroker) {
"changeInitiativeLifecyclePhase");
});

return $q
.all([schemesPromise, assessmentDefinitionsPromise, enumPromise]);
}


vm.$onChanges = (changes) => {
const sameParent = isSameParentEntityRef(changes);

if (vm.parentEntityRef && !sameParent) {
const selectionOptions = mkSelectionOptions(vm.parentEntityRef);
const ciPromise = serviceBroker
.loadViewData(
CORE_API.ChangeInitiativeStore.findHierarchyBySelector,
[ selectionOptions ])
.then(r => vm.changeInitiatives = r.data);

const assessmentRatingsPromise = serviceBroker
const viewPromise = serviceBroker
.loadViewData(
CORE_API.AssessmentRatingStore.findByTargetKindForRelatedSelector,
[ "CHANGE_INITIATIVE", selectionOptions ])
.then(r => vm.assessmentRatings = r.data);
CORE_API.ChangeInitiativeViewStore.findByEntity,
[vm.parentEntityRef])
.then(r => {
const d = r.data;
vm.changeInitiatives = d.changeInitiatives;
vm.assessmentRatings = d.ratings;
vm.ratingSchemeItems = d.ratingSchemeItems;
vm.assessmentDefinitions = d.assessmentDefinitions;
});

$q.all([init(), ciPromise, assessmentRatingsPromise])
$q.all([enumPromise, viewPromise])
.then(() => applyFilters());
}
};

function applyFilters() {

const retiredCiFilter = vm.displayRetiredCis
? () => true
: ci => ci.lifecyclePhase !== "RETIRED";
Expand All @@ -226,14 +284,13 @@ function controller($q, serviceBroker) {

vm.assessmentSummaries = mkAssessmentSummaries(
vm.assessmentDefinitions,
vm.ratingSchemes,
vm.ratingSchemeItems,
inScopeRatings,
inScopeCis.length);

vm.gridOptions.data = mkTableData(
relevantCis,
vm.changeInitiativeLifecyclePhaseByKey);

}

vm.onSelectAssessmentRating = d => {
Expand Down
14 changes: 9 additions & 5 deletions waltz-ng/client/change-initiative/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

import angular from "angular";

import {registerComponents, registerStore} from "../common/module-utils";
import {registerComponents, registerStores} from "../common/module-utils";

import changeInitiativeStore from "./services/change-initiative-store";
import changeInitiativeViewStore from "./services/change-initiative-view-store";
import changeInitiativeSelector from "./directives/change-initiative-selector";
import BulkChangeInitiativeSelector from "./components/bulk-change-initiative-selector/bulk-change-initiative-selector";

import BulkChangeInitiativeSelector from "./components/bulk-change-initiative-selector/bulk-change-initiative-selector";
import changeInitiativeSection from "./components/change-initiative-section/change-initiative-section";
import changeInitiativeTree from "./components/tree/change-initiative-tree";

import changeInitiativeTree from "./components/tree/change-initiative-tree";
import Routes from "./routes";


Expand All @@ -35,11 +36,14 @@ function setup() {
module
.config(Routes);

registerStore(module, changeInitiativeStore);
registerStores(module, [
changeInitiativeStore,
changeInitiativeViewStore
]);

module
.directive("waltzChangeInitiativeSelector", changeInitiativeSelector);

registerComponents(module, [
changeInitiativeSection,
changeInitiativeTree,
Expand Down
Loading

0 comments on commit c0a24cf

Please sign in to comment.