From de7b0f44f17e40d0901ea05ccff6a5dab27093d7 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Sun, 2 Dec 2018 21:06:05 -0600 Subject: [PATCH] WIP: sort injection order --- _locales/en/messages.json | 10 +++++++++- manage.html | 12 ++++++------ manage/draggable.js | 3 ++- manage/manage-actions.js | 17 ++++++++++++++++- manage/manage-ui.js | 7 ++++--- manage/sort.js | 2 +- 6 files changed, 38 insertions(+), 13 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index ac4da535..816024c0 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1258,9 +1258,17 @@ "description": "Title of sort column, indicating that the style can be manually sorted by dragging & dropping" }, "sortLabel": { - "message": "Click to sort; Shift + click to sort multiple columns", + "message": "Click to sort by \"$name$\";\nUse shift + click to sort by multiple items", + "placeholders": { + "name": { + "content": "$1" + } + }, "description": "Title added to links in the manager page header to inform the user on how to sort the columns" }, + "sortHeaderOrderLabel": { + "message": "Click and drag the icon to change the style injection order" + }, "styleBadRegexp": { "message": "Regexp is invalid.", "description": "Validation message for a bad regexp in a style" diff --git a/manage.html b/manage.html index 27927ea1..640ae3a4 100644 --- a/manage.html +++ b/manage.html @@ -380,15 +380,15 @@ - # - + # +
- +
-
- v# - +
+ v# +
diff --git a/manage/draggable.js b/manage/draggable.js index a4841fbc..55a25832 100644 --- a/manage/draggable.js +++ b/manage/draggable.js @@ -1,4 +1,4 @@ -/* global UI $$ */ +/* global UI $$ updateInjectionOrder */ 'use strict'; // Polyfill for mobile? - https://caniuse.com/#feat=dragndrop @@ -10,6 +10,7 @@ el.classList.remove('dragging'); }); $('body').classList.remove('dragging'); + updateInjectionOrder(); } document.addEventListener('dragstart', event => { diff --git a/manage/manage-actions.js b/manage/manage-actions.js index fc78456d..d0294641 100644 --- a/manage/manage-actions.js +++ b/manage/manage-actions.js @@ -5,11 +5,12 @@ global messageBox getStyleWithNoCode objectDiff configDialog sorter msg prefs API onDOMready $ $$ setupLivePrefs - URLS enforceInputRange t formatDate + URLS enforceInputRange t getOwnTab getActiveTab openURL animateElement sessionStorageHash debounce scrollElementIntoView FIREFOX UI */ +/* exported updateInjectionOrder */ 'use strict'; let installed; @@ -445,6 +446,20 @@ function removeSelection() { } } +function updateInjectionOrder() { + const entries = [...installed.children]; + entries.shift(); // remove header + console.log(entries[1].styleMeta.id, entries[1].styleMeta.injectionOrder) + + entries.forEach((entry, index) => { + entry.styleMeta.injectionOrder = index + 1; + $('.entry-id', entry).textContent = index + 1; + }); + sorter.update(); + + // TODO: Update database +} + function lazyLoad() { setTimeout(() => { $$('link[data-href]').forEach(link => { diff --git a/manage/manage-ui.js b/manage/manage-ui.js index ffcfd315..e0205e0e 100644 --- a/manage/manage-ui.js +++ b/manage/manage-ui.js @@ -141,7 +141,7 @@ const UI = { (style.updateUrl ? ' updatable' : '') + (style.usercssData ? ' usercss' : ''); - $('.entry-id', entry).textContent = style.sortOrder || style.id; + $('.entry-id', entry).textContent = style.injectionOrder || style.id; let el = $('.entry-homepage', entry); el.classList.toggle('invisible', !style.url); el.href = style.url || ''; @@ -282,12 +282,13 @@ const UI = { const label = document.createElement('a'); labels.className = 'header-labels'; label.className = 'header-label sortable'; - label.title = t('sortLabel'); label.href = '#'; Object.keys(UI.labels).forEach(item => { const newLabel = label.cloneNode(true); + const text = UI.labels[item].text; newLabel.dataset.type = item; - newLabel.textContent = UI.labels[item].text; + newLabel.textContent = text; + newLabel.title = t('sortLabel', text); labels.appendChild(newLabel); }); header.appendChild(labels); diff --git a/manage/sort.js b/manage/sort.js index fc25db4a..e3739772 100644 --- a/manage/sort.js +++ b/manage/sort.js @@ -26,7 +26,7 @@ const sorter = (() => { }, order: { text: '#', - parse: ({style}) => style.id, + parse: ({style}) => style.injectionOrder || style.id, sorter: sorterType.number, }, usercss: {