Skip to content

Commit 8bbfc5c

Browse files
committed
feat(taglist-order): add new option taglist-order
1 parent fbab517 commit 8bbfc5c

File tree

4 files changed

+11
-30
lines changed

4 files changed

+11
-30
lines changed

src/components/docker-registry-ui.riot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
5555
filter-results="{ state.filter }"
5656
on-authentication="{ onAuthentication }"
5757
use-control-cache-header="{ truthy(props.useControlCacheHeader) }"
58+
taglist-order="{ taglistOrderParser(props.taglistOrder) }"
5859
></tag-list>
5960
</route>
6061
<route path="{baseRoute}taghistory/(.*)">
@@ -129,6 +130,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
129130
import { stripHttps, getRegistryServers, setRegistryServers, truthy, stringToArray } from '../scripts/utils';
130131
import router from '../scripts/router';
131132
import { loadTheme } from '../scripts/theme';
133+
import { taglistOrderParser } from '../scripts/taglist-order';
132134
133135
export default {
134136
components: {
@@ -241,6 +243,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
241243
version,
242244
truthy,
243245
stringToArray,
246+
taglistOrderParser,
244247
};
245248
</script>
246249
<style>

src/components/tag-list/tag-list.riot

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
6161

6262
<script>
6363
import { Http } from '../../scripts/http';
64-
import { DockerImage, compare } from '../../scripts/docker-image';
64+
import { DockerImage } from '../../scripts/docker-image';
6565
import { getNumPages, getPageLabels } from '../../scripts/utils';
6666
import Pagination from './pagination.riot';
6767
import TagTable from './tag-table.riot';
6868
import router from '../../scripts/router';
69+
import { getTagComparator } from '../../scripts/taglist-order';
70+
6971
export default {
7072
components: {
7173
Pagination,
@@ -86,6 +88,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
8688
// this may be run before the final document size is available, so schedule
8789
// a correction once everything is set up.
8890
window.requestAnimationFrame(this.onResize);
91+
this.tagComparator = getTagComparator(props.taglistOrder);
8992
},
9093
display(props, state) {
9194
state.tags = [];
@@ -106,7 +109,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
106109
useControlCacheHeader: props.useControlCacheHeader,
107110
})
108111
)
109-
.sort(compare);
112+
.sort(self.tagComparator);
110113
window.requestAnimationFrame(self.onResize);
111114
self.update({
112115
page: Math.min(state.page, getNumPages(tags)),
@@ -168,7 +171,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
168171
this.state.tags.reverse();
169172
this.state.asc = false;
170173
} else {
171-
this.state.tags.sort(compare);
174+
this.state.tags.sort(this.tagComparator);
172175
this.state.asc = true;
173176
}
174177
this.update();

src/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
show-catalog-nb-tags="${SHOW_CATALOG_NB_TAGS}"
4848
history-custom-labels="${HISTORY_CUSTOM_LABELS}"
4949
use-control-cache-header="${USE_CONTROL_CACHE_HEADER}"
50+
taglist-order="${TAGLIST_ORDER}
5051
theme="${THEME}"
5152
theme-primary-text="${THEME_PRIMARY_TEXT}"
5253
theme-neutral-text="${THEME_NEUTRAL_TEXT}"
@@ -73,6 +74,7 @@
7374
show-catalog-nb-tags="true"
7475
history-custom-labels="first_custom_labels,second_custom_labels"
7576
use-control-cache-header="false"
77+
taglist-order="alpha-asc;num-desc"
7678
theme="auto"
7779
theme-primary-text=""
7880
theme-neutral-text=""

src/scripts/docker-image.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,6 @@ import { Http } from './http';
1818
import { isDigit, eventTransfer, ERROR_CAN_NOT_READ_CONTENT_DIGEST } from './utils';
1919
import observable from '@riotjs/observable';
2020

21-
const tagReduce = (acc, e) => {
22-
if (acc.length > 0 && isDigit(acc[acc.length - 1].charAt(0)) == isDigit(e)) {
23-
acc[acc.length - 1] += e;
24-
} else {
25-
acc.push(e);
26-
}
27-
return acc;
28-
};
29-
30-
export function compare(e1, e2) {
31-
const tag1 = e1.tag.match(/./g).reduce(tagReduce, []);
32-
const tag2 = e2.tag.match(/./g).reduce(tagReduce, []);
33-
34-
for (var i = 0; i < tag1.length && i < tag2.length; i++) {
35-
const compare = tag1[i].localeCompare(tag2[i]);
36-
if (isDigit(tag1[i].charAt(0)) && isDigit(tag2[i].charAt(0))) {
37-
const diff = tag1[i] - tag2[i];
38-
if (diff != 0) {
39-
return diff;
40-
}
41-
} else if (compare != 0) {
42-
return compare;
43-
}
44-
}
45-
return e1.tag.length - e2.tag.length;
46-
}
47-
4821
export class DockerImage {
4922
constructor(name, tag, { list, registryUrl, onNotify, onAuthentication, useControlCacheHeader }) {
5023
this.name = name;

0 commit comments

Comments
 (0)