Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better sorting and naming of static palettes in the Custom Palette Editor #3674

Merged
merged 1 commit into from
Jan 12, 2024
Merged
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
16 changes: 13 additions & 3 deletions wled00/data/cpal/cpal.htm
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ <h1 style="display: flex; align-items: center;">
var gradientLength = rect.width;
var mOffs = Math.round((gradientLength / 256) / 2) - 5;
var paletteArray = []; //Holds the palettes after load.
var paletteName = []; // Holds the names of the palettes after load.
var svgSave = '<svg style="width:25px;height:25px" viewBox="0 0 24 24"><path fill=#fff d="M22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2A10,10 0 0,1 22,12M7,12L12,17V14H16V10H12V7L7,12Z"/></svg>'
var svgEdit = '<svg style="width:25px;height:25px" viewBox="0 0 24 24"><path fill=#fff d="M12,2C6.47,2 2,6.47 2,12C2,17.53 6.47,22 12,22C17.53,22 22,17.53 22,12C22,6.47 17.53,2 12,2M15.1,7.07C15.24,7.07 15.38,7.12 15.5,7.23L16.77,8.5C17,8.72 17,9.07 16.77,9.28L15.77,10.28L13.72,8.23L14.72,7.23C14.82,7.12 14.96,7.07 15.1,7.07M13.13,8.81L15.19,10.87L9.13,16.93H7.07V14.87L13.13,8.81Z"/></svg>'

Expand Down Expand Up @@ -520,8 +521,10 @@ <h1 style="display: flex; align-items: center;">
if (hst.length > 0 ) {
try {
var arr = [];
const response = await fetch('http://'+hst+'/json/info');
const json = await response.json();
const responseInfo = await fetch('http://'+hst+'/json/info');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps also use getURL() logic from index.js which will work behind reverse proxy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did it like it was done before. But it you would prefer it we could also use getURL().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem I see is that if we do this we have to copy the code from index.js to cpal.htm and then we have created duplicate code again. We could wait with this until we have a global.js file that contains functions like getURL() that are used on every page, so we do not have to maintain the duplicate code. But I'll let you decide. Should I just copy the code now, or should we wait until we have a global.js file?

const responsePalettes = await fetch('http://'+hst+'/json/palettes');
const json = await responseInfo.json();
paletteName = await responsePalettes.json();
cpalc = json.cpalcount;
fetchPalettes(cpalc-1);
} catch (error) {
Expand Down Expand Up @@ -560,6 +563,7 @@ <h1 style="display: flex; align-items: center;">
alert("The cache of palettes are missig from your browser. You should probably return to the main page and let it load properly for the palettes cache to regenerate before returning here.","Missing cached palettes!")
} else {
for (const key in wledPalx.p) {
wledPalx.p[key].name = paletteName[key];
if (key > 245) {
delete wledPalx.p[key];
continue;
Expand Down Expand Up @@ -591,8 +595,11 @@ <h1 style="display: flex; align-items: center;">
}

const pArray = Object.entries(wledPalx.p).map(([key, value]) => ({
[key]: value.flat()
[key]: value.flat(),
name: value.name
}));
// Sort pArray by name
pArray.sort((a, b) => a.name.localeCompare(b.name));

paletteArray.push( ...pArray);
}
Expand Down Expand Up @@ -634,6 +641,9 @@ <h1 style="display: flex; align-items: center;">
editSpan.id = `editSpan${i}`;
editSpan.onclick = function() {loadForEdit(i)};
editSpan.setAttribute('title', `Copy slot ${i} palette to editor`);
if (paletteArray[i].name) {
editSpan.setAttribute('title', `Copy ${paletteArray[i].name} palette to editor`);
}
editSpan.innerHTML = svgEdit;
editSpan.classList.add("editSpan")

Expand Down
Loading