Skip to content

Commit

Permalink
Fix broken javascript tests for #751.
Browse files Browse the repository at this point in the history
  • Loading branch information
donkirkby committed Jan 31, 2019
1 parent 2050ceb commit 08688e2
Show file tree
Hide file tree
Showing 22 changed files with 461 additions and 1,128 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ contributions.

Run both the Webpack and Sass watchers simultaneously with `npm run watch:all`.

To debug TypeScript code in the browser, change the `devtool` setting in
`webpack.config.js`.

### Updating embedded icon files ###

Some icon files are stored as base64-encoded strings which describe PNG images
Expand Down
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = function(config) {
};
// simulate the way Django structures directories for static file serving
serveDjangoPath(cfgObj, {
'container': ['templates', 'static', 'test_assets'],
'pipeline': ['templates', 'static', 'test_assets'],
'portal': ['static'],
});
Expand Down
9 changes: 0 additions & 9 deletions kive/container/static/container/canvas/drydock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1340,15 +1340,6 @@ export class CanvasState {
this.dispatchChangeEvent({ removed: sel });
}

findMethodNode (method_pk: number): MethodNode {
for (let method of this.methods) {
if (method.pk === method_pk) {
return method;
}
}
return null;
}

findOutputNode (pk: number): OutputNode {
for (let output of this.outputs) {
if (output.pk === pk) {
Expand Down
6 changes: 6 additions & 0 deletions kive/container/static/container/canvas/drydock_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,12 @@ export class MethodNode extends BaseNode implements CNode {
this.n_inputs = Object.keys(inputs).length;
this.n_outputs = Object.keys(outputs).length;
this.h = Math.max(this.n_inputs, this.n_outputs) * this.spacing;
if (this.n_inputs === 0) {
throw "No inputs passed to MethodNode."
}
if (this.n_outputs === 0) {
throw "No outputs passed to MethodNode."
}

for (let input of this.inputs) {
this.addInput(input);
Expand Down
17 changes: 2 additions & 15 deletions kive/container/static/container/container_content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,11 @@ CanvasListeners.initResizeListeners(canvasState);
/**
* Part 2/8: Load initial pipeline data if present.
*/
let parent_revision_id;
let text = $("#initial_data").text();
let loader = new Pipeline(canvasState);
if (text) {
loader.setUpdateCtrl('#id_update');
loader.setRevertCtrl('#id_revert');
loader.loadFromString(text);
parent_revision_id = loader.pipeline.id;
loader.draw();
$(canvas).hide().fadeIn();
}
Expand Down Expand Up @@ -123,18 +120,8 @@ $view_menu.find('#autolayout_btn').click(
*/
$('#id_pipeline_form').submit(buildPipelineSubmit(
canvasState,
$('#id_pipeline_action').val(),
$('#id_family_name'), $('#id_family_desc'),
parseInt($('#id_family_pk').val(), 10),
$('#id_revision_name'), $('#id_revision_desc'),
parent_revision_id,
$('#published'),
$("#id_permissions_0"), $("#id_permissions_1"),
$('#id_submit_error'),
function() {
family_dialog.show();
$('#id_family_name').addClass('submit-error-missing').focus();
}
parseInt($('#id_container_pk').val(), 10),
$('#id_submit_error')
));

/**
Expand Down
10 changes: 6 additions & 4 deletions kive/container/static/container/io/PipelineApi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ export interface PipelineConfig {
threads: number;
}

export interface DataSource extends Point {
export interface DataSource {
x?: number;
y?: number;
dataset_name: string;
source_step: number;
source_dataset_name: string;
source_step?: number;
source_dataset_name?: string;
}

interface Step extends Point {
driver: string;
fill_colour: string;
fill_colour?: string;
inputs: DataSource[];
outputs: string[];
}
49 changes: 3 additions & 46 deletions kive/container/static/container/io/pipeline_load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {Container, PipelineData} from "./PipelineApi";
*/
export class Pipeline {

container: Container = null;
pipeline: PipelineData = null;
files: string[] = [];
private REVISION_API_URL = "/api/pipelines/";
Expand All @@ -26,6 +27,7 @@ export class Pipeline {
* @param container: serialized pipeline array
*/
load(container: Container) {
this.container = container;
this.pipeline = container.pipeline;
this.files = container.files;
this.canvasState.reset();
Expand Down Expand Up @@ -280,20 +282,6 @@ export class Pipeline {
return url.replace(host_pattern, "");
}

findNewStepRevisions() {
let steps = this.canvasState.getSteps();
Pipeline.updateSignalsOf(steps, "update in progress");
this.canvasState.valid = false;
RestApi.get(
Pipeline.stripHostFrom(this.pipeline.step_updates),
updates => this.applyStepRevisions(updates),
() => {
Pipeline.updateSignalsOf(steps, "unavailable");
this.canvasState.valid = false;
}
);
}

private static checkForCrrAndDepUpdates(method: MethodNode, update): boolean {
if (update.code_resource_revision) {
method.new_code_resource_revision = update.code_resource_revision;
Expand Down Expand Up @@ -338,39 +326,12 @@ export class Pipeline {
this.canvasState.valid = false;
}

/**
* Returns whether or not the pipeline has been published
*/
isPublished() {
return this.pipeline.published;
}

/**
* Sets this pipeline as published
* @todo test and utilize this!
*
* @param callback: Function called on success
*/
publish(callback) {
RestApi.patch(this.REVISION_API_URL + this.pipeline.id, { published: true }, callback);
}

/**
* Sets this pipeline as unpublished
* @todo test and utilize this!
*
* @param callback: Function called on success
*/
unpublish(callback) {
RestApi.patch(this.REVISION_API_URL + this.pipeline.id, { published: false }, callback);
}

setRevertCtrl(ctrl: string) {
document.querySelector(ctrl).addEventListener('click', () => {
let $canvas = $(this.canvasState.canvas);
$canvas.fadeOut({
complete: () => {
this.load(this.pipeline);
this.load(this.container);
$canvas.fadeIn();
}
});
Expand All @@ -380,9 +341,5 @@ export class Pipeline {
});

}

setUpdateCtrl(ctrl: string) {
document.querySelector(ctrl).addEventListener('click', () => this.findNewStepRevisions());
}
}

121 changes: 16 additions & 105 deletions kive/container/static/container/io/pipeline_submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,35 @@ import { CanvasState } from "../canvas/drydock";
import { RestApi } from "../rest_api.service";
import { serializePipeline } from "./serializer";

export function buildPipelineSubmit(canvasState: CanvasState, action: string, $family_name: JQuery,
$family_desc: JQuery, family_pk: number, $revision_name: JQuery, $revision_desc: JQuery,
parent_revision_id: number, $published: JQuery, $user_permissions: JQuery,
$group_permissions: JQuery, $error: JQuery, familyNameError: () => any) {

// $action, $family_pk, and parent_revision_id are static
export function buildPipelineSubmit(
canvasState: CanvasState,
container_pk: number,
$error: JQuery) {

if (!container_pk && container_pk !== 0) {
throw 'Container primary key must be specified';
}
if (!(canvasState instanceof CanvasState)) {
throw "Invalid object given as CanvasState.";
}
if (action === 'revise') {
if (typeof parent_revision_id !== 'number' || isNaN(parent_revision_id) || parent_revision_id < 0) {
throw 'Parent revision ID must be specified';
}
}
if (action === 'revise' || action === 'add') {
if (!family_pk && family_pk !== 0) {
throw 'Family primary key must be specified';
}
}
if ($family_name.length === 0) {
throw "Family name element could not be found.";
}
if ($family_desc.length === 0) {
throw "Family description element could not be found.";
}
if ($revision_name.length === 0) {
throw "Revision name element could not be found.";
}
if ($revision_desc.length === 0) {
throw "Revision name element could not be found.";
}
if ($published.length === 0) {
throw "Published checkbox element could not be found.";
}
if ($published.prop('checked') === undefined) {
throw "Published checkbox element does not conform to spec.";
}
if ($user_permissions.length === 0) {
throw "User permissions widget could not be found.";
}
if ($group_permissions.length === 0) {
throw "Group permissions widget could not be found.";
}
if ($error.length === 0) {
throw "User error message element could not be found.";
}
if (typeof familyNameError !== "function") {
throw "Error function callback was not supplied or not callable.";
}

/*
* Trigger AJAX transaction on submitting form.
*/
return function(e) {
e.preventDefault(); // override form submit action
clearErrors($error);
let family = $family_name.val();
if (action === "new" && family === '') {
familyNameError();
submitError('Pipeline family must be named', $error);
} else {
try {
// @todo: action can also be 'add' when pipeline family exists with 0 revisions
let form_data = serializePipeline(
canvasState,
{
users_allowed: getPermissionsArray($user_permissions),
groups_allowed: getPermissionsArray($group_permissions),

// There is no PipelineFamily yet; we're going to create one.
family,
family_desc: $family_desc.val(),

// arguments to add first pipeline revision
revision_name: $revision_name.val(),
revision_desc: $revision_desc.val(),
revision_parent: action === 'revise' ? parent_revision_id : null,
published: $published.prop('checked'),
try {
// @todo: action can also be 'add' when pipeline family exists with 0 revisions
let form_data = serializePipeline(canvasState);

// Canvas information to store in the Pipeline object.
canvas_width: canvasState.width,
canvas_height: canvasState.height
}
);
submitPipelineAjax(container_pk, form_data, $error);

if (action !== "new") {
submitPipelineAjax(family_pk, form_data, $error);
} else { // Pushing a new family
submitPipelineFamilyAjax({
users_allowed: form_data.users_allowed,
groups_allowed: form_data.groups_allowed,
name: form_data.family,
description: form_data.family_desc
}, $error).done(function (result) {
submitPipelineAjax(result.id, form_data, $error);
});
}

} catch (e) {
submitError(e, $error);
}
} catch (e) {
submitError(e, $error);
}
};
}
Expand Down Expand Up @@ -145,13 +72,13 @@ function submitError(errors, $error) {
$error.show();
setTimeout(() => $error.hide(), 8000);
}
function submitPipelineAjax(family_pk, form_data, $error) {
function submitPipelineAjax(container_pk, form_data, $error) {
return RestApi.post(
'/api/pipelines/',
'/api/containers/' + container_pk + '/content',
JSON.stringify(form_data),
function() {
$(window).off('beforeunload');
window.location.href = '/pipelines/' + family_pk;
window.location.href = '/container_update/' + container_pk;
},
function (xhr, status, error) {
let json = xhr.responseJSON;
Expand All @@ -172,19 +99,3 @@ function submitPipelineAjax(family_pk, form_data, $error) {
}
);
}
function submitPipelineFamilyAjax(family_form_data, $error) {
return RestApi.post(
'/api/pipelinefamilies/',
JSON.stringify(family_form_data),
() => {},
function(xhr, status, error) {
let json = xhr.responseJSON;
let serverErrors = json &&
(json.non_field_errors || json.detail) || [];
if (serverErrors.length === 0) {
serverErrors = xhr.status + " - " + error;
}
submitError(serverErrors, $error);
}
);
}
Loading

0 comments on commit 08688e2

Please sign in to comment.