Skip to content

Commit

Permalink
missed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bengarrett committed Dec 17, 2023
1 parent f222db2 commit 96d47bb
Show file tree
Hide file tree
Showing 7 changed files with 347 additions and 84 deletions.
244 changes: 177 additions & 67 deletions assets/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"use strict";

const danger = `text-danger`;
const err = `is-invalid`;
const ok = `is-valid`;
const fok = `valid-feedback`;
const ferr = `invalid-feedback`;
const hide = `d-none`;
const header = {
"Content-type": "application/json; charset=UTF-8",
};
Expand All @@ -16,7 +21,7 @@
return;
}

// Modify the file metadata, online and public
// Modify the file metadata, File artifact is online and public
const online = document.getElementById(`recordOnline`);
const onlineL = document.getElementById(`recordOnlineLabel`);
if (online.checked != true) {
Expand Down Expand Up @@ -50,136 +55,230 @@
});
});

// recordTitle
// Modify the file metadata, Title
const recTitle = document.getElementById(`recordTitle`);
recTitle.addEventListener(`input`, function (event) {
recTitle.value = recTitle.value.trimStart();
if (recTitle.value == ``) {
recTitle.classList.add(danger);
return;
}
recTitle.classList.remove(danger);
});

// releasers
const releasers = document.getElementById(`recordReleasers`);
const releasersMax = document.getElementById(`recordReleasersMax`);
releasers.addEventListener(`input`, function (event) {
// enforce text input
releasers.value = releasers.value.toUpperCase();
releasers.value = releasers.value.replace(/[^a-zA-Z0-9-+& ]/g, "");
if (releasers.value == ``) {
releasers.classList.add(err);
return;
}
releasers.classList.remove(err);
// enforce max releasers
const count = releasers.value.split(`+`).length;
const maximum = 2;
if (count > maximum) {
releasers.classList.add(err);
releasersMax.classList.add(dang);
const infoErr = document.getElementById(`recordTitleErr`);
const ogLabel = document.getElementById(`recordTitleOG`);
const ogText = document.getElementById(`recordTitleOGValue`).textContent;
if (recTitle.value != ogText && recTitle.value.length > 0) {
ogLabel.classList.remove(hide);
} else {
releasers.classList.remove(err);
releasersMax.classList.remove(dang);
ogLabel.classList.add(hide);
}
recTitle.classList.remove(err);
infoErr.classList.add(hide);
fetch("/editor/title", {
method: "POST",
body: JSON.stringify({
id: parseInt(id.value),
value: recTitle.value,
}),
headers: header,
})
.then((response) => {
if (!response.ok) {
throw new Error(saveErr);
}
infoErr.classList.add(hide);
recTitle.classList.remove(err);
recTitle.classList.add(ok);
return response.json();
})
.catch((error) => {
infoErr.classList.remove(hide);
recTitle.classList.add(err);
console.log(error.message);
});
});

// // hyphen to underscore
// re := regexp.MustCompile(`\-`)
// s = re.ReplaceAllString(s, "_")
// // multiple groups get separated with asterisk
// re = regexp.MustCompile(`\, `)
// s = re.ReplaceAllString(s, "*")
// // any & characters need replacement due to HTML escaping
// re = regexp.MustCompile(` \& `)
// s = re.ReplaceAllString(s, " ampersand ")
// // numbers receive a leading hyphen
// re = regexp.MustCompile(` ([0-9])`)
// s = re.ReplaceAllString(s, "-$1")
// // delete all other characters
// const deleteAllExcept = `[^A-Za-z0-9 \-\+\.\_\*]`
// re = regexp.MustCompile(deleteAllExcept)
// s = re.ReplaceAllString(s, "")
// // trim whitespace and replace any space separators with hyphens
// s = strings.TrimSpace(strings.ToLower(s))
// re = regexp.MustCompile(` `)
// s = re.ReplaceAllString(s, "-")
// Modify the file metadata, Year, month, day of release, save button
const recYMDSave = document.getElementById(`recordYMDSave`);
recYMDSave.addEventListener(`click`, function (event) {
year.classList.remove(ok);
month.classList.remove(ok);
day.classList.remove(ok);
fetch("/editor/ymd", {
method: "POST",
body: JSON.stringify({
id: parseInt(id.value),
year: parseInt(year.value),
month: parseInt(month.value),
day: parseInt(day.value),
}),
headers: header,
})
.then((response) => {
if (!response.ok) {
throw new Error(saveErr);
}
year.classList.add(ok);
month.classList.add(ok);
day.classList.add(ok);
recYMDSave.classList.remove(danger);
return response.json();
})
.catch((error) => {
recYMDSave.classList.add(danger);
console.log(error.message);
});
});

// release dates
// Modify the file metadata, Year, month, day of release, Use last modification button
document
.getElementById(`recordLMBtn`)
.addEventListener(`click`, function (event) {
year.classList.remove(err);
month.classList.remove(err);
day.classList.remove(err);
year.classList.remove(ok);
month.classList.remove(ok);
day.classList.remove(ok);
const split = document.getElementById(`recordLastMod`).value.split(`-`);
if (split.length != 3) {
console.error(`invalid last modified date provided by server`);
return;
}
year.value = split[0];
month.value = split[1];
day.value = split[2];
});

// Modify the file metadata, Year, month, day of release, reset button
document
.getElementById(`recordYMDReset`)
.addEventListener(`click`, function (event) {
const ogy = document.getElementById(`recordOgY`).value;
const ogm = document.getElementById(`recordOgM`).value;
const ogd = document.getElementById(`recordOgD`).value;
year.value = ogy;
month.value = ogm;
day.value = ogd;
year.classList.remove(err);
month.classList.remove(err);
day.classList.remove(err);
year.classList.remove(ok);
month.classList.remove(ok);
day.classList.remove(ok);
recYMDSave.disabled = false;
});

// Modify the file metadata, Year, month, day of release
const year = document.getElementById(`recordYear`);
const month = document.getElementById(`recordMonth`);
const day = document.getElementById(`recordDay`);
year.addEventListener(`input`, function (event) {
if (year.value >= 1980 && year.value <= 2023) {
year.classList.remove(err);
recYMDSave.disabled = false;
return;
}
// year can only be empty when month and day are empty
if (year.value == `` && month.value == `` && day.value == ``) {
year.classList.remove(err);
month.classList.remove(err);
day.classList.remove(err);
recYMDSave.disabled = false;
return;
}
year.classList.add(err);
recYMDSave.disabled = true;
});
month.addEventListener(`input`, function (event) {
if (month.value >= 1 && month.value <= 12) {
month.classList.remove(err);
recYMDSave.disabled = false;
return;
}
if (year.value == `` && month.value == `` && day.value == ``) {
year.classList.remove(err);
month.classList.remove(err);
day.classList.remove(err);
recYMDSave.disabled = false;
return;
}
// month can only be empty when day is empty
if (month.value == `` && day.value == ``) {
month.classList.remove(err);
day.classList.remove(err);
recYMDSave.disabled = false;
return;
}
month.classList.add(err);
recYMDSave.disabled = true;
});
day.addEventListener(`input`, function (event) {
if (month.value >= 1 && month.value <= 31) {
month.classList.remove(err);
if (day.value >= 1 && day.value <= 31) {
day.classList.remove(err);
recYMDSave.disabled = false;
return;
}
if (year.value == `` && month.value == `` && day.value == ``) {
year.classList.remove(err);
month.classList.remove(err);
day.classList.remove(err);
recYMDSave.disabled = false;
return;
}
if (month.value == `` && day.value == ``) {
month.classList.remove(err);
day.classList.remove(err);
recYMDSave.disabled = false;
return;
}
if (day.value == ``) {
day.classList.remove(err);
recYMDSave.disabled = false;
return;
}
day.classList.add(err);
recYMDSave.disabled = true;
});

// last modification button
const lmBtn = document.getElementById(`recordLMBtn`);
const lm = document.getElementById(`recordLastMod`);
if (typeof lmBtn !== `undefined` && lmBtn !== null) {
lmBtn.addEventListener(`click`, function (event) {
const split = lm.value.split(`-`);
if (split.length != 3) {
return;
}
year.value = split[0];
month.value = split[1];
day.value = split[2];
});
}
// releasers
const releasers = document.getElementById(`recordReleasers`);
const releasersMax = document.getElementById(`recordReleasersMax`);
releasers.addEventListener(`input`, function (event) {
// enforce text input
releasers.value = releasers.value.toUpperCase();
releasers.value = releasers.value.replace(/[^a-zA-Z0-9-+& ]/g, "");
if (releasers.value == ``) {
releasers.classList.add(err);
return;
}
releasers.classList.remove(err);
// enforce max releasers
const count = releasers.value.split(`+`).length;
const maximum = 2;
if (count > maximum) {
releasers.classList.add(err);
releasersMax.classList.add(dang);
} else {
releasers.classList.remove(err);
releasersMax.classList.remove(dang);
}

// // hyphen to underscore
// re := regexp.MustCompile(`\-`)
// s = re.ReplaceAllString(s, "_")
// // multiple groups get separated with asterisk
// re = regexp.MustCompile(`\, `)
// s = re.ReplaceAllString(s, "*")
// // any & characters need replacement due to HTML escaping
// re = regexp.MustCompile(` \& `)
// s = re.ReplaceAllString(s, " ampersand ")
// // numbers receive a leading hyphen
// re = regexp.MustCompile(` ([0-9])`)
// s = re.ReplaceAllString(s, "-$1")
// // delete all other characters
// const deleteAllExcept = `[^A-Za-z0-9 \-\+\.\_\*]`
// re = regexp.MustCompile(deleteAllExcept)
// s = re.ReplaceAllString(s, "")
// // trim whitespace and replace any space separators with hyphens
// s = strings.TrimSpace(strings.ToLower(s))
// re = regexp.MustCompile(` `)
// s = re.ReplaceAllString(s, "-")
});

// people
function parseName(name) {
Expand Down Expand Up @@ -414,8 +513,19 @@
filename.classList.remove(err);
});

// Modify the file metadata, Platform and Tag
const platform = document.getElementById(`recordPlatform`);
const tag = document.getElementById(`recordTag`);

document.getElementById(`recTagsReset`).addEventListener(`click`, function () {
const ogp = document.getElementById(`recOSOg`).value;
const ogt = document.getElementById(`recTagOg`).value;
platform.value = ogp;
tag.value = ogt;
});



const releaserL = document.getElementById(`recordReleasersLabel`);
const titleL = document.getElementById(`recordTitleLabel`);

Expand Down
2 changes: 2 additions & 0 deletions handler/app/render_about.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func (a Dirs) About(z *zap.SugaredLogger, c echo.Context, readonly bool) error {
data["recAnsiLoveList"] = OptionsAnsiLove(res.FileZipContent.String)
data["recReadmeSug"] = readmeSuggest(res)
data["recZipContent"] = strings.TrimSpace(res.FileZipContent.String)
data["recOS"] = strings.ToLower(strings.TrimSpace(res.Platform.String))
data["recTag"] = strings.ToLower(strings.TrimSpace(res.Section.String))
}
// page metadata
data["uuid"] = uuid
Expand Down
Loading

0 comments on commit 96d47bb

Please sign in to comment.