Skip to content

Commit

Permalink
Merge pull request #6950 from deutschebank/db-contrib/waltz-6708-mand…
Browse files Browse the repository at this point in the history
…atory-comments-on-assessments

mandatory comments on assessments
  • Loading branch information
davidwatkins73 authored Jan 22, 2024
2 parents 405973c + ddecb95 commit f037923
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public class RatingSchemeDAO {

RatingSchemeItemRecord r = record.into(RATING_SCHEME_ITEM);

ImmutableRatingSchemeItem.Builder builder = ImmutableRatingSchemeItem.builder()
ImmutableRatingSchemeItem.Builder builder = ImmutableRatingSchemeItem
.builder()
.id(r.getId())
.ratingSchemeId(r.getSchemeId())
.name(r.getName())
Expand All @@ -81,7 +82,8 @@ public class RatingSchemeDAO {
.position(r.getPosition())
.description(r.getDescription())
.externalId(ofNullable(r.getExternalId()))
.ratingGroup(r.getRatingGroup());
.ratingGroup(r.getRatingGroup())
.requiresComment(r.getRequiresComment());


if (record.field(IS_RESTRICTED_FIELD) != null){
Expand Down Expand Up @@ -245,6 +247,7 @@ public Long saveRatingItem(long schemeId,
r.setPosition(item.position());
r.setUserSelectable(item.userSelectable());
r.setRatingGroup(item.ratingGroup());
r.setRequiresComment(item.requiresComment());

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public boolean userSelectable() {
@Nullable
public abstract String ratingGroup();

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

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<script>
import _ from "lodash";
import {assessmentRatings, primaryEntityReference, selectedAssessment} from "./rating-store";
import {assessmentRatingStore} from "../../../svelte-stores/assessment-rating-store";
import Icon from "../../../common/svelte/Icon.svelte";
import toasts from "../../../svelte-stores/toast-store";
import {displayError} from "../../../common/error-utils";
let dropdownConfig;
let assessmentRatingCall;
import Markdown from "../../../common/svelte/Markdown.svelte";
export let onCancel;
Expand All @@ -18,6 +14,9 @@
comment: null
};
let dropdownConfig;
let assessmentRatingCall;
function onSave() {
const seletedDefnId = $selectedAssessment.definition.id;
assessmentRatingStore
Expand All @@ -32,7 +31,6 @@
}
$: {
const existingRatings = _.map($selectedAssessment.ratings, d => d.rating.ratingId);
const grouped = _
Expand All @@ -50,9 +48,11 @@
dropdownConfig = grouped[null]
? {style: "simple", options: grouped[null]}
: {style: "grouped", groups: _.map(grouped, (v, k) => ({groupName: k, options: v}))};
}
$: selectedRating = _.find(
$selectedAssessment.dropdownEntries,
d => d.id === newRating.ratingId);
</script>
<h4>Add New Rating:</h4>
Expand Down Expand Up @@ -83,27 +83,48 @@
{/each}
{/if}
</select>
<div class="help-block">
{#if selectedRating}
<Markdown text={selectedRating.description}/>
{:else}
Please select a rating
{/if}
</div>
</div>
<div class="form-group">
<label for="comment">
Comment
Comment {#if selectedRating?.requiresComment}<span class="required-indicator">*</span>{/if}
</label>
<textarea id="comment"
class="form-control"
rows="6"
required={selectedRating?.requiresComment}
placeholder="This comment supports markdown"
bind:value={newRating.comment}></textarea>
{#if selectedRating?.requiresComment}
<div class="help-block">
A comment is mandatory for this rating
</div>
{/if}
</div>
<button type="submit"
class="btn btn-skinny">
<Icon name="floppy-o"/>
Save
</button>
<button class="btn btn-skinny"
on:click={onCancel}>
<Icon name="times"/>
Cancel
</button>
</form>
<button class="btn btn-skinny"
on:click={onSave}>
<Icon name="floppy-o"/>
Save
</button>
<button class="btn btn-skinny"
on:click={onCancel}>
<Icon name="times"/>
Cancel
</button>
<style>
.required-indicator {
color: red;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import {displayError} from "../../../common/error-utils";
import {cardinality} from "../../../common/services/enums/cardinality";
import EditableRatingValue from "./EditableRatingValue.svelte";
import Markdown from "../../../common/svelte/Markdown.svelte";
export let onCancel;
export let onRemove;
Expand Down Expand Up @@ -134,6 +135,9 @@
showGroup={true}
disablementReason={ratingDisablementReason}
onSave={saveRating}/>
<div class="help-block">
<Markdown text={$selectedRating.ratingItem.description}/>
</div>
</div>
</div>
Expand All @@ -142,6 +146,7 @@
<div id="comment">
<TextEditableField text={rating.comment}
label="Comment"
mandatory={$selectedRating.ratingItem.requiresComment}
editable={canEdit}
onSave={saveComment}/>
</div>
Expand Down
91 changes: 52 additions & 39 deletions waltz-ng/client/common/svelte/TextEditableField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
export let onSave = (text) => console.log("Text to save", {text});
export let editable;
export let label;
export let mandatory = false;
let workingText;
let savePromise
Expand Down Expand Up @@ -37,52 +38,64 @@
savePromise
.then(() => activeMode = Modes.VIEW);
}
</script>


{#if activeMode === Modes.VIEW}
{#if !_.isEmpty(label)}
<label for="text">
{label}
</label>
{#if editable}
<button class="btn btn-skinny"
<span class="waltz-visibility-parent">
{#if activeMode === Modes.VIEW}
{#if !_.isEmpty(label)}
<label for="text">
{label} {#if mandatory}*{/if}
</label>
{#if editable}
<button class="btn btn-skinny waltz-visibility-child-50"
on:click={editText}>
<Icon name="pencil"/>
Edit
</button>
{/if}
{/if}
<div id="text">
<Markdown {text}/>
</div>
{#if mandatory}
<div class="help-block">
A comment is mandatory
</div>
{/if}
{#if _.isEmpty(label) && editable}
<button class="btn btn-skinny waltz-visibility-child-50"
on:click={editText}>
<Icon name="pencil"/>
Edit
</button>
{/if}
{/if}
<div id="text">
<Markdown {text}/>
</div>
{#if _.isEmpty(label) && editable}
{:else if activeMode === Modes.EDIT}
{#if !_.isEmpty(label)}
<label for="text">
{label} {#if mandatory}*{/if}
</label>
{/if}
<textarea class="form-control"
rows="5"
required={mandatory}
bind:value={workingText}></textarea>
{#if mandatory}
<div class="help-block">
A comment is mandatory
</div>
{/if}
<button class="btn btn-skinny"
on:click={editText}>
<Icon name="pencil"/>
Edit
disabled={mandatory && _.isEmpty(_.trim(workingText))}
on:click={save}>
<Icon name="floppy-o"/>
Save
</button>
<button class="btn btn-skinny"
on:click={() => activeMode = Modes.VIEW}>
<Icon name="times"/>
Cancel
</button>
{:else if activeMode === Modes.SAVING}
<SavingPlaceholder/>
{/if}
{:else if activeMode === Modes.EDIT}
{#if !_.isEmpty(label)}
<label for="text">
{label}
</label>
{/if}
<textarea class="form-control"
rows="5"
bind:value={workingText}/>
<button class="btn btn-skinny"
on:click={save}>
<Icon name="floppy-o"/>
Save
</button>
<button class="btn btn-skinny"
on:click={() => activeMode = Modes.VIEW}>
<Icon name="times"/>
Cancel
</button>
{:else if activeMode === Modes.SAVING}
<SavingPlaceholder/>
{/if}
</span>
21 changes: 21 additions & 0 deletions waltz-ng/client/system/svelte/ratings-schemes/ItemEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@
</div>


<!-- REQUIRES COMMENT -->
<label for="requiresComment">
Requires Comment ?
</label>
<input type=checkbox
id="requiresComment"
bind:checked={workingCopy.requiresComment}>
<span class="text-muted">
{#if workingCopy.requiresComment}
Yes, user must supply a comment when selecting this item
<Icon name="lock"/>
{:else}
No, users may omit providing a comment when selecting this item
<Icon name="unlock"/>
{/if}
</span>
<div class="help-block">
Determines if the user <i>must</i> supply a comment when selecting this item.
</div>


<!-- COLOR -->
<label for="color-picker">Color</label>
<div id="color-picker">
Expand Down
17 changes: 12 additions & 5 deletions waltz-ng/client/system/svelte/ratings-schemes/ItemsView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,17 @@
{/if}

{#if activeMode === Modes.LIST}
<table class="table table-striped table-hover table-condensed">
<table class="table table-striped table-hover table-condensed small">
<thead>
<tr>
<th width="20%"><i>Group</i></th>
<th width="25%">Rating</th>
<th width="5%">Code</th>
<th width="10%">Req. Comment</th>

<th width="10%">Color</th>
<th width="15%">Usages</th>
<th width="25%">Operations</th>
<th width="10%">Usages</th>
<th width="20%">Operations</th>
</tr>
</thead>
<tbody>
Expand All @@ -114,6 +116,11 @@
<td>{rating.ratingGroup || '-'}</td>
<td>{rating.name}</td>
<td>{rating.rating}</td>
<td>
{#if rating.requiresComment}
<Icon name="check"/>
{/if}
</td>
<td>
<div class="rating-square"
style="background-color: {rating.color}">
Expand Down Expand Up @@ -142,13 +149,13 @@
</tr>
{:else}
<tr>
<td colspan="5">No ratings yet</td>
<td colspan="7">No ratings yet</td>
</tr>
{/each}
</tbody>
<tfoot>
<tr>
<td colspan="5">
<td colspan="7">
<button class="btn-link"
on:click={mkNew}>
<Icon name="plus"/>
Expand Down
16 changes: 16 additions & 0 deletions waltz-schema/src/main/resources/liquibase/db.changelog-1.57.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,20 @@
tableName="software_version" />
</changeSet>


<changeSet id="20240117-6708-2"
author="davidwatkins73">
<comment>6708: Allow assessments to require mandatory comments</comment>
<addColumn tableName="rating_scheme_item">
<column name="requires_comment"
type="boolean"
defaultValueBoolean="false">
<constraints nullable="false"/>
</column>
</addColumn>
<setColumnRemarks tableName="rating_scheme_item"
columnName="requires_comment"
remarks="Indicates if the user must provide a comment when setting this option. Only valid if the assessment/item is not-readonly and is user-selectable"/>
</changeSet>

</databaseChangeLog>

0 comments on commit f037923

Please sign in to comment.