44 */
55package com .artipie .front .ui .repository ;
66
7+ import com .amihaiemil .eoyaml .Yaml ;
8+ import com .amihaiemil .eoyaml .YamlMapping ;
79import com .artipie .front .Layout ;
810import com .artipie .front .misc .RouteWrap ;
911import com .artipie .front .rest .RepositoryService ;
1012import com .artipie .front .rest .SettingsService ;
1113import com .artipie .front .ui .HbPage ;
14+ import java .io .IOException ;
15+ import java .util .ArrayList ;
1216import java .util .List ;
1317import java .util .Map ;
18+ import java .util .Optional ;
1419
1520/**
1621 * List of repositories page.
@@ -33,12 +38,23 @@ public RepoList(final RepositoryService repository, final SettingsService settin
3338 req -> {
3439 final String uid = req .session ().attribute ("uid" );
3540 final String token = req .session ().attribute ("token" );
36- final List <String > repos ;
41+ final List <String > names ;
3742 if (settings .layout () == Layout .FLAT ) {
38- repos = repository .list (token );
43+ names = repository .list (token );
3944 } else {
40- repos = repository .list (token , uid );
45+ names = repository .list (token , uid );
4146 }
47+ final List <Repo > repos = new ArrayList <>(names .size ());
48+ names .stream ().sorted ().forEach (
49+ name ->
50+ repos .add (
51+ new Repo (
52+ Integer .toString (settings .port ()),
53+ name ,
54+ repository .repo (token , name )
55+ )
56+ )
57+ );
4258 return Map .of (
4359 "title" , "Repository list" ,
4460 "repos" , repos
@@ -47,4 +63,75 @@ public RepoList(final RepositoryService repository, final SettingsService settin
4763 )
4864 );
4965 }
66+
67+ /**
68+ * Repository information.
69+ * @since 0.1.3
70+ */
71+ @ SuppressWarnings ("PMD.AvoidFieldNameMatchingMethodName" )
72+ public static class Repo {
73+ /**
74+ * Repository name.
75+ */
76+ private final String name ;
77+
78+ /**
79+ * Artipie server port.
80+ */
81+ private final String port ;
82+
83+ /**
84+ * Repository configuration.
85+ */
86+ private Optional <YamlMapping > conf ;
87+
88+ /**
89+ * Ctor.
90+ * @param port Artipie's default port
91+ * @param name Name of repository.
92+ * @param conf Repository configuration content
93+ */
94+ @ SuppressWarnings ("PMD.ConstructorOnlyInitializesOrCallOtherConstructors" )
95+ public Repo (final String port , final String name , final String conf ) {
96+ this .port = port ;
97+ this .name = name ;
98+ try {
99+ this .conf = Optional .of (Yaml .createYamlInput (conf ).readYamlMapping ());
100+ } catch (final IOException exc ) {
101+ this .conf = Optional .empty ();
102+ }
103+ }
104+
105+ /**
106+ * Name of repository.
107+ * @return Name of repository.
108+ */
109+ public String name () {
110+ return this .name ;
111+ }
112+
113+ /**
114+ * Type of repository defined in configuration.
115+ * @return Repository type or empty string
116+ */
117+ public String type () {
118+ return this .repo ().map (repo -> repo .string ("type" )).orElse ("" );
119+ }
120+
121+ /**
122+ * Port of repository defined in configuration.
123+ * @return Repository port or default Artipie port
124+ */
125+ public String port () {
126+ return this .repo ().map (repo -> repo .string ("port" )).orElse (this .port );
127+ }
128+
129+ /**
130+ * Repository repo-section in yaml.
131+ * @return Repository repo-configuration
132+ */
133+ private Optional <YamlMapping > repo () {
134+ return this .conf .map (value -> value .yamlMapping ("repo" ));
135+ }
136+ }
50137}
0 commit comments