-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: Improve web-ui for listing of repositories #114
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,18 @@ | |
*/ | ||
package com.artipie.front.ui.repository; | ||
|
||
import com.amihaiemil.eoyaml.Yaml; | ||
import com.amihaiemil.eoyaml.YamlMapping; | ||
import com.artipie.front.Layout; | ||
import com.artipie.front.misc.RouteWrap; | ||
import com.artipie.front.rest.RepositoryService; | ||
import com.artipie.front.rest.SettingsService; | ||
import com.artipie.front.ui.HbPage; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** | ||
* List of repositories page. | ||
|
@@ -33,12 +38,23 @@ public RepoList(final RepositoryService repository, final SettingsService settin | |
req -> { | ||
final String uid = req.session().attribute("uid"); | ||
final String token = req.session().attribute("token"); | ||
final List<String> repos; | ||
final List<String> names; | ||
if (settings.layout() == Layout.FLAT) { | ||
repos = repository.list(token); | ||
names = repository.list(token); | ||
} else { | ||
repos = repository.list(token, uid); | ||
names = repository.list(token, uid); | ||
} | ||
final List<Repo> repos = new ArrayList<>(names.size()); | ||
names.stream().sorted().forEach( | ||
name -> | ||
repos.add( | ||
new Repo( | ||
Integer.toString(settings.port()), | ||
name, | ||
repository.repo(token, name) | ||
) | ||
) | ||
); | ||
return Map.of( | ||
"title", "Repository list", | ||
"repos", repos | ||
|
@@ -47,4 +63,76 @@ public RepoList(final RepositoryService repository, final SettingsService settin | |
) | ||
); | ||
} | ||
|
||
/** | ||
* Repository information. | ||
* @since 0.1.3 | ||
*/ | ||
public static class Repo { | ||
/** | ||
* Repository name. | ||
*/ | ||
@SuppressWarnings("PMD.AvoidFieldNameMatchingMethodName") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, one suppression on class level should be enough There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andpopov what about this one? Is qulice still complaining if you move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. qulice works correctly, fixed. |
||
private final String name; | ||
|
||
/** | ||
* Artipie server port. | ||
*/ | ||
@SuppressWarnings("PMD.AvoidFieldNameMatchingMethodName") | ||
private final String port; | ||
|
||
/** | ||
* Repository configuration. | ||
*/ | ||
private Optional<YamlMapping> conf; | ||
|
||
/** | ||
* Ctor. | ||
* @param port Artipie's default port | ||
* @param name Name of repository. | ||
* @param conf Repository configuration content | ||
*/ | ||
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors") | ||
public Repo(final String port, final String name, final String conf) { | ||
this.port = port; | ||
this.name = name; | ||
try { | ||
this.conf = Optional.of(Yaml.createYamlInput(conf).readYamlMapping()); | ||
} catch (final IOException exc) { | ||
this.conf = Optional.empty(); | ||
} | ||
} | ||
|
||
/** | ||
* Name of repository. | ||
* @return Name of repository. | ||
*/ | ||
public String name() { | ||
return this.name; | ||
} | ||
|
||
/** | ||
* Type of repository defined in configuration. | ||
* @return Repository type or empty string | ||
*/ | ||
public String type() { | ||
return this.repo().map(repo -> repo.string("type")).orElse(""); | ||
} | ||
|
||
/** | ||
* Port of repository defined in configuration. | ||
* @return Repository port or default Artipie port | ||
*/ | ||
public String port() { | ||
return this.repo().map(repo -> repo.string("port")).orElse(this.port); | ||
} | ||
|
||
/** | ||
* Repository repo-section in yaml. | ||
* @return Repository repo-configuration | ||
*/ | ||
private Optional<YamlMapping> repo() { | ||
return this.conf.map(value -> value.yamlMapping("repo")); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javadoc is wrong :)