Skip to content

Commit

Permalink
Merge pull request #6363 from davidwatkins73/waltz-6360-grouped-ratin…
Browse files Browse the repository at this point in the history
…gs-ui

Grouped ratings UI
  • Loading branch information
jessica-woodland-scott-db authored Jan 6, 2023
2 parents ad10259 + e728d61 commit e0fdf3e
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,28 @@

package org.finos.waltz.data.rating_scheme;

import org.finos.waltz.schema.Tables;
import org.finos.waltz.schema.tables.records.RatingSchemeItemRecord;
import org.finos.waltz.schema.tables.records.RatingSchemeRecord;
import org.finos.waltz.model.EntityKind;
import org.finos.waltz.model.EntityReference;
import org.finos.waltz.model.rating.*;
import org.finos.waltz.schema.Tables;
import org.finos.waltz.schema.tables.records.RatingSchemeItemRecord;
import org.finos.waltz.schema.tables.records.RatingSchemeRecord;
import org.jooq.*;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.*;

import static org.finos.waltz.schema.Tables.*;
import static org.finos.waltz.schema.tables.MeasurableCategory.MEASURABLE_CATEGORY;
import static org.finos.waltz.schema.tables.RatingScheme.RATING_SCHEME;
import static org.finos.waltz.schema.tables.RatingSchemeItem.RATING_SCHEME_ITEM;
import static java.util.Collections.emptyList;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toList;
import static org.finos.waltz.common.Checks.checkNotNull;
import static org.finos.waltz.common.MapUtilities.groupBy;
import static org.finos.waltz.common.StringUtilities.firstChar;
import static org.finos.waltz.schema.Tables.*;
import static org.finos.waltz.schema.tables.MeasurableCategory.MEASURABLE_CATEGORY;
import static org.finos.waltz.schema.tables.RatingScheme.RATING_SCHEME;
import static org.finos.waltz.schema.tables.RatingSchemeItem.RATING_SCHEME_ITEM;

@Repository
public class RatingSchemeDAO {
Expand All @@ -61,12 +60,13 @@ public class RatingSchemeDAO {
.id(r.getId())
.ratingSchemeId(r.getSchemeId())
.name(r.getName())
.rating(firstChar(r.getCode(), 'X'))
.rating(r.getCode())
.userSelectable(r.getUserSelectable())
.color(r.getColor())
.position(r.getPosition())
.description(r.getDescription())
.externalId(ofNullable(r.getExternalId()));
.externalId(ofNullable(r.getExternalId()))
.ratingGroup(r.getRatingGroup());


if (record.field(IS_RESTRICTED_FIELD) != null){
Expand All @@ -82,6 +82,7 @@ public class RatingSchemeDAO {
.id(r.getId())
.name(r.getName())
.description(r.getDescription())
.externalId(ofNullable(r.getExternalId()))
.build();


Expand Down Expand Up @@ -186,8 +187,10 @@ public Boolean save(RatingScheme scheme) {
RatingSchemeRecord r = dsl.newRecord(RATING_SCHEME);
r.setName(scheme.name());
r.setDescription(scheme.description());
r.setExternalId(scheme.externalId().orElse(null));

return scheme.id()
return scheme
.id()
.map(id -> {
r.setId(id);
r.changed(RATING_SCHEME.ID, false);
Expand All @@ -204,10 +207,11 @@ public Long saveRatingItem(long schemeId,
r.setSchemeId(schemeId);
r.setName(item.name());
r.setDescription(item.description());
r.setCode(Character.toString(item.rating()));
r.setCode(item.rating());
r.setColor(item.color());
r.setPosition(item.position());
r.setUserSelectable(item.userSelectable());
r.setRatingGroup(item.ratingGroup());

item.externalId().ifPresent(r::setExternalId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.finos.waltz.model.DescriptionProvider;
import org.finos.waltz.model.ExternalIdProvider;
import org.finos.waltz.model.IdProvider;
import org.finos.waltz.model.NameProvider;
import org.immutables.value.Value;
Expand All @@ -35,7 +36,8 @@
public abstract class RatingScheme implements
IdProvider,
NameProvider,
DescriptionProvider {
DescriptionProvider,
ExternalIdProvider {

@Value.Default
public List<RatingSchemeItem> ratings() {
Expand All @@ -44,7 +46,7 @@ public List<RatingSchemeItem> ratings() {

private static final RatingSchemeItem dfltR = ImmutableRatingSchemeItem.builder()
.ratingSchemeId(1)
.rating('R')
.rating("R")
.name("dflt - Disinvest")
.description("dflt - Disinvest")
.color("#d62728")
Expand All @@ -54,7 +56,7 @@ public List<RatingSchemeItem> ratings() {

private static final RatingSchemeItem dfltA = ImmutableRatingSchemeItem.builder()
.ratingSchemeId(1)
.rating('A')
.rating("A")
.name("dflt - Maintain")
.description("dflt - Maintain")
.color("#ff7f0e")
Expand All @@ -64,7 +66,7 @@ public List<RatingSchemeItem> ratings() {

private static final RatingSchemeItem dfltG = ImmutableRatingSchemeItem.builder()
.ratingSchemeId(1)
.rating('G')
.rating("G")
.name("dflt - Invest")
.description("dflt - Invest")
.color("#2ca02c")
Expand All @@ -73,7 +75,7 @@ public List<RatingSchemeItem> ratings() {

private static final RatingSchemeItem dfltT = ImmutableRatingSchemeItem.builder()
.ratingSchemeId(1)
.rating('F')
.rating("F")
.name("dflt - Future")
.description("dflt - Future")
.color("#786aa5")
Expand All @@ -84,7 +86,7 @@ public List<RatingSchemeItem> ratings() {

private static final RatingSchemeItem dfltZ = ImmutableRatingSchemeItem.builder()
.ratingSchemeId(1)
.rating('Z')
.rating("Z")
.name("dflt - Unknown")
.description("dflt - Unknown")
.color("#28a1b6")
Expand All @@ -95,7 +97,7 @@ public List<RatingSchemeItem> ratings() {

private static final RatingSchemeItem dfltX = ImmutableRatingSchemeItem.builder()
.ratingSchemeId(1)
.rating('X')
.rating("X")
.name("dflt - Not Applicable")
.description("dflt - Not Applicable")
.color("#eee")
Expand All @@ -114,11 +116,4 @@ public static List<RatingSchemeItem> toList() {
dfltZ);
}

public static RatingScheme mkDflt() {
return ImmutableRatingScheme.builder()
.id(1)
.name("default")
.description("default rating scheme")
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public abstract class RatingSchemeItem implements
PositionProvider,
ExternalIdProvider {

public abstract Character rating();
public abstract String rating();

public abstract String color();

public abstract long ratingSchemeId();

@Value.Default
Expand All @@ -45,4 +47,8 @@ public boolean userSelectable() {

@Value.Default
public boolean isRestricted() { return false; }

@Nullable
public abstract String ratingGroup();

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public abstract class ChangeScenarioCommand implements Command {
public abstract long rowId();
public abstract long ratingSchemeId();
@Nullable
public abstract Character rating();
public abstract String rating();
@Nullable
public abstract Character previousRating();
public abstract String previousRating();
@Nullable
public abstract String comment();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
let mode = Modes.VIEW;
let actions = [];
let dropdownConfig;
function onEdit() {
$form = Object.assign({}, assessment.rating);
Expand Down Expand Up @@ -125,6 +126,22 @@
]);
}
$: {
const grouped = _
.chain(assessment.dropdownEntries)
.sortBy([d => d.ratingGroup, d => d.position, d => d.name])
.groupBy("ratingGroup")
.value();
if (grouped[null] && _.size(grouped) > 1) {
grouped["Ungrouped"] = grouped[null];
delete grouped[null];
}
dropdownConfig = grouped[null]
? {style : "simple", options: grouped[null] }
: {style : "grouped", groups: _.map(grouped, (v, k) => ({groupName: k, options: v}))};
}
</script>

<SubSection>
Expand Down Expand Up @@ -157,11 +174,23 @@
<select id="rating-dropdown"
class="form-control"
bind:value={$form.ratingId}>
{#each assessment.dropdownEntries as entry}
<option value={entry.id}>
{entry.name}
</option>
{/each}
{#if dropdownConfig.style === 'simple'}
{#each dropdownConfig.options as entry}
<option value={entry.id}>
{entry.name}
</option>
{/each}
{:else if dropdownConfig.style === 'grouped'}
{#each dropdownConfig.groups as g}
<optgroup label={g.groupName}>
{#each g.options as entry}
<option value={entry.id}>
{entry.name}
</option>
{/each}
</optgroup>
{/each}
{/if}
</select>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
</td>
<td>
{#if assessment.ratingItem}
{#if assessment.ratingItem.ratingGroup}
<span class="text-muted">
{assessment.ratingItem.ratingGroup} /
</span>
{/if}
<RatingIndicatorCell {...assessment.ratingItem}
show-name="true"/>
{:else}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
&::after {
padding-left: 10px;
padding-right: 10px;
content: '\f00c';
font-family: 'FontAwesome';
content: "\2713";
}
}
}
Expand Down
17 changes: 15 additions & 2 deletions waltz-ng/client/system/svelte/ratings-schemes/ItemEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@
Short name which describes this rating scheme item
</div>

<!-- GROUP? -->
<label for="group">
Group
<small class="text-muted">(optional)</small>
</label>
<input class="form-control"
id="group"
placeholder="Optional grouping of rating item"
bind:value={workingCopy.ratingGroup}>
<div class="help-block">
Optional group name to categorize this rating scheme item
</div>


<!-- CODE -->
<label for="code">
Expand All @@ -79,11 +92,11 @@
style="width: 3em"
required="required"
disabled={workingCopy.id}
maxlength="1"
maxlength="3"
placeholder=""
bind:value={workingCopy.rating}>
<div class="help-block">
Single letter code to represent this rating scheme item
Short code (maximum of 3 chars) to represent this rating scheme item
{#if workingCopy.id}
<br>
<Icon name="warning"/>
Expand Down
14 changes: 6 additions & 8 deletions waltz-ng/client/system/svelte/ratings-schemes/ItemsView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,18 @@
<table class="table table-striped table-hover table-condensed">
<thead>
<tr>
<th width="20%">Rating</th>
<th width="20%"><i>Group</i></th>
<th width="25%">Rating</th>
<th width="5%">Code</th>
<th width="15%">Color</th>
<th width="20%">Description</th>
<th width="20%">Usages</th>
<th width="20%">Operations</th>
<th width="10%">Color</th>
<th width="15%">Usages</th>
<th width="25%">Operations</th>
</tr>
</thead>
<tbody>
{#each ratings as rating}
<tr>
<td>{rating.ratingGroup || '-'}</td>
<td>{rating.name}</td>
<td>{rating.rating}</td>
<td>
Expand All @@ -119,9 +120,6 @@
</div>
{rating.color}
</td>
<td>
{rating.description}
</td>
<td>
{usageCountsByRatingId[rating.id] || "-"}
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from "lodash";
export function sortItems(items = []) {
return _.orderBy(
items,
["position", "name"])
["ratingGroup", "position", "name"])
}

export function countUsageStatsBy(usageData, accessor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<property name="provenance.type" value="VARCHAR(64)"></property>
<property name="rag.type" value="CHAR(1)"></property>
<property name="role.type" value="VARCHAR(255)"></property>
<property name="short-code.type" value="CHAR(3)"></property>
<property name="short-code.type" value="VARCHAR(3)"></property>
<property name="tag.type" value="VARCHAR(255)"></property>
<property name="url.type" value="VARCHAR(500)"></property>
<property name="user-agent.type" value="VARCHAR(500)"></property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ private void writeApplicationChangeLog(ChangeScenarioCommand command, String use
changeLogService.write(mkBasicLogEntry(command.scenarioId(), message, userId));
}

private String getRatingName(List<RatingSchemeItem> ratings, char rating) {
Optional<RatingSchemeItem> ratingOptional = ratings.stream().filter(r -> r.rating() == rating).findFirst();
private String getRatingName(List<RatingSchemeItem> ratings, String rating) {
Optional<RatingSchemeItem> ratingOptional = ratings.stream().filter(r -> r.rating().equals(rating)).findFirst();
return ratingOptional.isPresent() ? ratingOptional.get().name() : "Unknown";
}
}

0 comments on commit e0fdf3e

Please sign in to comment.