Skip to content

Commit

Permalink
Tweaking
Browse files Browse the repository at this point in the history
- search fix for change breakdown table
- calendar heatmap deals with year boundaries correctly
- change summaries cleaned up
- change log sample generator slightly more realistic

finos#4876
  • Loading branch information
davidwatkins73 committed Jul 14, 2020
1 parent f9fc22a commit 227ebbc
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,56 @@

package com.khartec.waltz.jobs.generators;

import com.khartec.waltz.common.ArrayUtilities;
import com.khartec.waltz.common.SetUtilities;
import com.khartec.waltz.model.EntityKind;
import com.khartec.waltz.model.Severity;
import com.khartec.waltz.schema.tables.records.ChangeLogRecord;
import org.jooq.DSLContext;
import org.jooq.lambda.tuple.Tuple2;
import org.springframework.context.ApplicationContext;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

import static com.khartec.waltz.common.RandomUtilities.randomIntBetween;
import static com.khartec.waltz.common.RandomUtilities.randomPick;
import static com.khartec.waltz.schema.tables.Application.APPLICATION;
import static com.khartec.waltz.schema.tables.ChangeLog.CHANGE_LOG;
import static com.khartec.waltz.schema.tables.Person.PERSON;
import static java.time.LocalDateTime.now;
import static java.util.stream.Collectors.toSet;
import static org.jooq.lambda.tuple.Tuple.tuple;

public class ChangeLogGenerator implements SampleDataGenerator {

private static final String[] messages = new String[] {
"Updated the application",
"Modified the application",
"Enriched the application",
"Added to the application",
"Removed data from the application"
};
private static final Set<Tuple2<String, EntityKind>> messages = SetUtilities.asSet(
tuple("Updated the application", EntityKind.APPLICATION),
tuple("Modified the application", EntityKind.APPLICATION),
tuple("Enriched the application", EntityKind.APPLICATION),
tuple("Added to the application", EntityKind.APPLICATION),
tuple("Removed data from the application", EntityKind.APPLICATION),
tuple("Added flow", EntityKind.LOGICAL_DATA_FLOW),
tuple("Removed flow", EntityKind.LOGICAL_DATA_FLOW),
tuple("Added Physical flow", EntityKind.PHYSICAL_FLOW),
tuple("Removed Physical flow", EntityKind.PHYSICAL_FLOW));


private static ChangeLogRecord mkChangeLog(long appId, String email) {
private static ChangeLogRecord mkChangeLog(long appId, String email, LocalDateTime when) {
Tuple2<String, EntityKind> messageTemplate = randomPick(messages);

ChangeLogRecord record = new ChangeLogRecord();
record.setMessage(randomPick(messages));
record.setMessage(messageTemplate.v1);
record.setParentId(appId);
record.setParentKind(EntityKind.APPLICATION.name());
record.setChildKind(messageTemplate.v2.name());
record.setUserId(email);
record.setSeverity(Severity.INFORMATION.name());
record.setCreatedAt(Timestamp.valueOf(when));

return record;
}
Expand All @@ -74,9 +88,15 @@ public Map<String, Integer> create(ApplicationContext ctx) {
.fetch(PERSON.EMAIL);

Set<ChangeLogRecord> records = emails.stream()
.flatMap(email -> Stream.of(
mkChangeLog(randomPick(appIds), email),
mkChangeLog(randomPick(appIds), randomPick(emails))))
.flatMap(email -> {
Long appId = randomPick(appIds);
LocalDateTime when = now().minus(randomIntBetween(0, 365), ChronoUnit.DAYS);
return Stream.of(
mkChangeLog(appId, email, when),
mkChangeLog(appId, email, when),
mkChangeLog(randomPick(appIds), email, when),
mkChangeLog(appId, randomPick(emails), when));
})
.collect(toSet());

dsl.batchInsert(records).execute();
Expand Down
20 changes: 11 additions & 9 deletions waltz-ng/client/change-log/components/change-breakdown-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,24 @@
</span>
</div>
<div ng-if="$ctrl.selectedDate">
<h4>Changes for
<span ng-bind="$ctrl.selectedDate | date:'yyyy-MM-dd'"></span>:
<h5>
<span ng-bind="$ctrl.selectedDate | date:'yyyy-MM-dd'"></span>
changes
<span ng-if="$ctrl.total" class="text-muted">
( Total: <span ng-bind="$ctrl.total"></span> )
</span>
<a class="pull-right clickable"
ng-click="$ctrl.clearSelectedDate()">
(x)
<waltz-icon name="times" title="Close"></waltz-icon>
</a>
</h4>
</h5>

<waltz-loading-notification show="$ctrl.visibility.loading"
style="padding-top: 54px;"
style="height: 200px"
name="Loading">
</waltz-loading-notification>

<div ng-if="!$ctrl.visibility.loading">
<div style="margin-top: 4px" class="small text-muted">
(Total: <span ng-bind="$ctrl.total"></span>)
</div>
<br>
<waltz-no-data ng-if="$ctrl.data.length == 0">
<message>
There are no changes on this date
Expand Down
13 changes: 7 additions & 6 deletions waltz-ng/client/change-log/components/change-breakdown-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ const initialState = {
};


function controller(serviceBroker, $q) {
function controller(serviceBroker) {

const vm = initialiseData(this, initialState);

vm.columnDefs = [
{
field: "ref",
name: "Entity",
toSearchTerm: d => d.ref.name,
cellTemplate:`
<div class="ui-grid-cell-contents">
<waltz-entity-link entity-ref="COL_FIELD"
Expand All @@ -61,13 +62,14 @@ function controller(serviceBroker, $q) {
function loadChangeSummaries(opts) {
vm.visibility.loading = true;
serviceBroker
.loadViewData(CORE_API.ChangeLogSummariesStore.findSummariesForKindBySelector,
.loadViewData(
CORE_API.ChangeLogSummariesStore.findSummariesForKindBySelector,
["APPLICATION", opts, vm.selectedDate])
.then(r => {
vm.data = r.data;
vm.total = _.sumBy(vm.data, "count");
vm.visibility.loading = false;
})
});
}

vm.$onInit = () => {
Expand All @@ -84,13 +86,12 @@ function controller(serviceBroker, $q) {

vm.clearSelectedDate = () => {
vm.selectedDate = null;
}
};
}


controller.$inject = [
"ServiceBroker",
"$q"
"ServiceBroker"
];


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import {initialiseData} from "../../../common";
import template from './change-summaries-panel.html';
import template from "./change-summaries-panel.html";
import {mkSelectionOptions} from "../../../common/selector-utils";
import {CORE_API} from "../../../common/services/core-api-utils";

Expand Down Expand Up @@ -50,7 +50,7 @@ function controller(serviceBroker) {

vm.onSelectDate = (date) => {
vm.selectedDate = date;
}
};
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,22 @@ function drawMonthLabels(svg, rawData, nestedData) {

/**
* We dynamically determine a color scale based on the maximum
* value. If the number is large then we use a sqrt scale, otherwise
* we use a linear scale.
* count value in the `rawData`. If the number is large then we
* use a sqrt scale, otherwise we use a linear scale.
*
* @param actualMax
* @param rawData
* @returns {*}
*/
function determineColorScale(actualMax) {
function determineColorScale(rawData) {
const actualMax = _.get(_.maxBy(rawData, "count"), ["count"], 0);

return (actualMax > 100)
? scaleSqrt()
.domain([1, _.min([1000, actualMax])])
.range(COLORS.filledCellRange)
.clamp(true)
: scaleLinear()
.domain([1, _.min([1000, actualMax])])
.domain([1, actualMax])
.range(COLORS.filledCellRange)
.clamp(true);
}
Expand All @@ -194,9 +196,7 @@ function draw(rawData, holder, onSelect) {
const w = DIMENSIONS.margins.left + DIMENSIONS.margins.right + (maxOffset * DIMENSIONS.cellSize);
const h = DIMENSIONS.margins.top + DIMENSIONS.margins.bottom + (7 * DIMENSIONS.cellSize);

const actualMax = _.get(_.maxBy(rawData, "count"), ["count"], 0);

const colorScale = determineColorScale(actualMax);
const colorScale = determineColorScale(rawData);

const svg = select(holder)
.append("svg")
Expand Down Expand Up @@ -254,12 +254,15 @@ function draw(rawData, holder, onSelect) {
function controller(serviceBroker, $element, $timeout) {
const vm = initialiseData(this, initData);

vm.$onInit = () => {
};
// wrap the callback in $timeout to make angular aware of the event
const clickHandler = d => $timeout(() => vm.onSelectDate(d));

vm.$onChanges = (c) => {
if(c.data && vm.data != null){
draw(prepareData(vm.data), $element[0], d => $timeout(() => vm.onSelectDate(d)));
if(c.data && vm.data != null) {
draw(
prepareData(vm.data),
$element[0],
clickHandler);
}
};
}
Expand Down

0 comments on commit 227ebbc

Please sign in to comment.