Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

[Web Portal] Replace the suffix if a cloned job is resubmited #2451

Merged
merged 3 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/webportal/src/app/job/job-submit/job-submit.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ const jobSubmitHtml = jobSubmitComponent({
let editor;
let jobDefaultConfig;

const getChecksum = (str) => {
let res = 0;
for (const c of str) {
res^= c.charCodeAt(0) & 0xff;
}
return res.toString(16);
};

const isValidJson = (str) => {
let valid = true;
let errors = null;
Expand Down Expand Up @@ -173,9 +181,17 @@ $(document).ready(() => {
url: url,
type: 'GET',
success: (data) => {
let jobConfigObj = JSON.parse(data);
let timestamp = Date.now();
jobConfigObj.jobName += `_${timestamp}`;
let jobConfigObj = data;
if (typeof(jobConfigObj) === 'string') {
jobConfigObj = JSON.parse(data);
}
let name = jobConfigObj.jobName;
if (/_\w{8}$/.test(name) && getChecksum(name.slice(0, -2)) === name.slice(-2)) {
name = name.slice(0, -9);
}
name = `${name}_${Date.now().toString(16).substr(0, 6)}`;
name = name + getChecksum(name);
jobConfigObj.jobName = name;
editor.setValue(Object.assign({}, jobDefaultConfig, jobConfigObj));
},
error: (xhr, textStatus, error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ $(document).ready(() => {
if (type != null && username != null && jobname != null) {
const url = `${webportalConfig.restServerUri}/api/v1/user/${username}/jobs/${jobname}/config`;
$.get(url, (data) => {
userTemplate.updatePageFromYaml(data);
if (typeof data === 'string') {
userTemplate.updatePageFromYaml(data);
} else {
userTemplate.updatePageFromJson(data);
}
$('#submitJob').attr('disabled', false);
});
}
Expand Down