Skip to content

Commit

Permalink
Merge pull request #6150 from deutschebank/db-contrib/waltz-6098-asse…
Browse files Browse the repository at this point in the history
…ssment-ratings-into-groups

Db contrib/waltz 6098 assessment ratings into groups
  • Loading branch information
davidwatkins73 authored Jul 26, 2022
2 parents 72f6db9 + 87ce214 commit 996a4f0
Show file tree
Hide file tree
Showing 22 changed files with 671 additions and 86 deletions.
1 change: 1 addition & 0 deletions waltz-data/src/main/ddl/liquibase/db.changelog-1.43.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,5 @@
<column name="user_selectable" valueBoolean="true"/>
</insert>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class AssessmentDefinitionDao {
.isReadOnly(record.getIsReadonly())
.provenance(record.getProvenance())
.visibility(AssessmentVisibility.valueOf(record.getVisibility()))
.definitionGroup(record.getDefinitionGroup())
.qualifierReference(maybeReadRef(
record,
ASSESSMENT_DEFINITION.QUALIFIER_KIND,
Expand Down Expand Up @@ -114,6 +115,7 @@ public Collection<AssessmentDefinition> findByEntityKindAndQualifier(EntityKind
/**
* Saves the given assessment definition. Either updating or inserting.
* Returns the identifier for the record.
*
* @param def the definition to save
* @return the identifier for the record
*/
Expand All @@ -138,15 +140,16 @@ public Long save(AssessmentDefinition def) {
r.setLastUpdatedAt(Timestamp.valueOf(def.lastUpdatedAt()));
r.setLastUpdatedBy(def.lastUpdatedBy());
r.setProvenance(StringUtilities.ifEmpty(def.provenance(), "waltz"));
r.setDefinitionGroup(r.getDefinitionGroup());

def.qualifierReference()
.ifPresent(qualifier -> {
r.setQualifierId(qualifier.id());
r.setQualifierKind(qualifier.kind().name());
});
.ifPresent(qualifier -> {
r.setQualifierId(qualifier.id());
r.setQualifierKind(qualifier.kind().name());
});

def.id()
.ifPresent(r::setId);
.ifPresent(r::setId);

if (r.getId() == null) {
r.insert();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public abstract class AssessmentDefinition implements

public abstract AssessmentVisibility visibility();

@Value.Default
public String definitionGroup() {
return "Uncategorized";
}

@Value.Default
public EntityKind kind() {
return EntityKind.ASSESSMENT_DEFINITION;
Expand Down
15 changes: 15 additions & 0 deletions waltz-ng/client/assessments/assessment-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,19 @@ function loadAssessments($q, serviceBroker, kind, ratingsPromise, primaryOnly =
assessmentsByEntityId: enrichedByEntityId // assessmentsByEntityId: entity id -> assessment def external id -> assessment
};
});
}


export function isFavourite(favouriteDefinitionIds, id) {
return _.includes(favouriteDefinitionIds, id);
}


export function getIdsFromString(includedFavouritesString) {
return _.isNil(includedFavouritesString)
? []
: _.chain(includedFavouritesString.value)
.split(",")
.map(idString => _.toNumber(idString))
.value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import Markdown from "../../../common/svelte/Markdown.svelte";
import Icon from "../../../common/svelte/Icon.svelte";
import {fade} from 'svelte/transition';
export let assessment;
$: console.log({assessment});
</script>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import {initialiseData} from "../../../common";
import _ from "lodash";
import template from "./assessment-rating-favourites-list.html";
import {mkAssessmentDefinitionsIdsKey} from "../../../user";
import {mkAssessmentDefinitionsIdsBaseKey} from "../../../user";
import {CORE_API} from "../../../common/services/core-api-utils";


Expand Down Expand Up @@ -82,7 +82,7 @@ function controller(serviceBroker) {
serviceBroker
.loadAppData(CORE_API.UserPreferenceStore.findAllForUser, [], {force: true})
.then(r => vm.favouriteAssessmentDefnIds = getFavouriteAssessmentDefnIds(
mkAssessmentDefinitionsIdsKey(vm.parentEntityRef),
mkAssessmentDefinitionsIdsBaseKey(vm.parentEntityRef),
r.data,
vm.defaultPrimaryList))
.then(() => filterAssessments());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<script>
import Markdown from "../../../common/svelte/Markdown.svelte";
import Icon from "../../../common/svelte/Icon.svelte";
export let definition;
</script>


<h4>
{definition.name}
<span class="text-muted small">({definition.externalId})</span>
</h4>
<Markdown class="force-wrap" text={definition.description}/>

{#if definition.isReadOnly}
<div class="help-block small">
<Icon name="lock"/>
Assessments relating to this definition are read-only and cannot be edited.
</div>
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<script>
import _ from "lodash";
import {userPreferenceStore} from "../../../svelte-stores/user-preference-store";
import {onMount} from "svelte";
import {createStores} from "./assessment-rating-store";
import AssessmentRatingListGroup from "./AssessmentRatingListGroup.svelte";
import Icon from "../../../common/svelte/Icon.svelte";
let elem;
let stores = null;
let defaultPrimaryList;
let favouriteIncludedIds;
let favouriteExcludedIds;
let favouriteIds;
let setFromPreferences;
let userPreferenceCall = userPreferenceStore.findAllForUser();
export let assessments = [];
export let primaryEntityRef = [];
export let onSelect = (d) => console.log("selected", d);
onMount(() => {
userPreferenceCall = userPreferenceStore.findAllForUser();
})
function toggleGroup(group) {
expansions = _.includes(expansions, group.groupName)
? _.without(expansions, group.groupName)
: _.concat(expansions, group.groupName);
}
function selectAssessment(evt) {
onSelect(evt.detail);
}
function toggleFavourite(row) {
const isExplicitlyIncluded = _.includes($favouriteIncludedIds, row.definition.id);
const isExplicitlyExcluded = _.includes($favouriteExcludedIds, row.definition.id);
const isDefault = _.includes($defaultPrimaryList, row.definition.id);
let message;
if (isExplicitlyIncluded) {
message = "Removing from favourite assessments"
$favouriteIncludedIds = _.without($favouriteIncludedIds, row.definition.id);
} else if (isExplicitlyExcluded) {
message = "Adding to favourite assessments"
$favouriteExcludedIds = _.without($favouriteExcludedIds, row.definition.id);
} else if (isDefault) {
message = "Removing from favourite assessments"
$favouriteExcludedIds = _.concat($favouriteExcludedIds, row.definition.id);
} else {
message = "Adding to favourite assessments"
$favouriteIncludedIds = _.concat($favouriteIncludedIds, row.definition.id);
}
}
$: {
if (primaryEntityRef) {
stores = createStores(primaryEntityRef);
defaultPrimaryList = stores.defaultPrimaryList
favouriteIncludedIds = stores.favouriteIncludedIds,
favouriteExcludedIds = stores.favouriteExcludedIds,
favouriteIds = stores.favouriteIds,
setFromPreferences = stores.setFromPreferences
}
}
$: userPreferences = $userPreferenceCall.data;
$: {
if (userPreferences && stores) {
setFromPreferences(userPreferences)
}
}
$: expansions = _
.chain(assessments)
.filter(d => _.includes($favouriteIds, d.definition.id))
.map(d => d.definition.definitionGroup)
.uniq()
.value();
$: groupedAssessments = _.chain(assessments)
.groupBy(d => d.definition?.definitionGroup)
.map((v, k) => {
const [notProvided, provided] = _
.chain(v)
.orderBy(d => d.definition.name)
.partition(d => d.rating == null)
.value()
return {
groupName: k,
notProvided,
provided
}
})
.orderBy([d => d.groupName === "Uncategorized", d => d.groupName])
.value();
$: {
if (stores) {
$defaultPrimaryList = _
.chain(assessments)
.filter(a => a.definition.visibility === "PRIMARY")
.map(r => r.definition.id)
.value();
}
}
</script>
<div class="row">
<div class="col-sm-12">
<table class="table table-hover table-condensed">
<colgroup>
<col width="10%"/>
<col width="50%"/>
<col width="40%"/>
</colgroup>
{#each groupedAssessments as group}
<tbody>
<tr style="background-color: #eee">
<td>
<button class="btn btn-skinny"
on:click={() => toggleGroup(group)}>
<Icon size="lg"
name={_.includes(expansions, group.groupName) ? "caret-down" : "caret-right"}/>
</button>
</td>
<td colspan="2">
<strong>
<span>{group.groupName}</span>
</strong>
</td>
</tr>
{#if _.includes(expansions, group.groupName)}
<AssessmentRatingListGroup group={group}
on:select={selectAssessment}
toggleFavourite={toggleFavourite}
favouriteIds={favouriteIds}/>
{/if}
</tbody>
{/each}
</table>
</div>
</div>
Loading

0 comments on commit 996a4f0

Please sign in to comment.