use of com.gitblit.wicket.ng.NgController in project gitblit by gitblit.
the class FilterableRepositoryList method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
String id = getId();
String ngCtrl = id + "Ctrl";
String ngList = id + "List";
Map<String, Object> values = new HashMap<String, Object>();
values.put("ngCtrl", ngCtrl);
values.put("ngList", ngList);
// use Freemarker to setup an AngularJS/Wicket html snippet
FreemarkerPanel panel = new FreemarkerPanel("listComponent", "FilterableRepositoryList.fm", values);
panel.setParseGeneratedMarkup(true);
panel.setRenderBodyOnly(true);
add(panel);
// add the Wicket controls that are referenced in the snippet
String listTitle = StringUtils.isEmpty(title) ? getString("gb.repositories") : title;
panel.add(new Label(ngList + "Title", MessageFormat.format("{0} ({1})", listTitle, repositories.size())));
if (StringUtils.isEmpty(iconClass)) {
panel.add(new Label(ngList + "Icon").setVisible(false));
} else {
Label icon = new Label(ngList + "Icon");
WicketUtils.setCssClass(icon, iconClass);
panel.add(icon);
}
if (allowCreate) {
panel.add(new LinkPanel(ngList + "Button", "btn btn-mini", getString("gb.newRepository"), app().getNewRepositoryPage()));
} else {
panel.add(new Label(ngList + "Button").setVisible(false));
}
String format = app().settings().getString(Keys.web.datestampShortFormat, "MM/dd/yy");
final DateFormat df = new SimpleDateFormat(format);
df.setTimeZone(getTimeZone());
// prepare the simplified repository models list
List<RepoListItem> list = new ArrayList<RepoListItem>();
for (RepositoryModel repo : repositories) {
String name = StringUtils.stripDotGit(repo.name);
String path = "";
if (name.indexOf('/') > -1) {
path = name.substring(0, name.lastIndexOf('/') + 1);
name = name.substring(name.lastIndexOf('/') + 1);
}
RepoListItem item = new RepoListItem();
item.n = name;
item.p = path;
item.r = repo.name;
item.i = repo.description;
item.s = app().repositories().getStarCount(repo);
item.t = getTimeUtils().timeAgo(repo.lastChange);
item.d = df.format(repo.lastChange);
item.c = StringUtils.getColor(StringUtils.stripDotGit(repo.name));
if (!repo.isBare) {
item.y = 3;
} else if (repo.isMirror) {
item.y = 2;
} else if (repo.isFork()) {
item.y = 1;
} else {
item.y = 0;
}
list.add(item);
}
// inject an AngularJS controller with static data
NgController ctrl = new NgController(ngCtrl);
ctrl.addVariable(ngList, list);
add(new HeaderContributor(ctrl));
}
use of com.gitblit.wicket.ng.NgController in project gitblit by gitblit.
the class FilterableProjectList method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
String id = getId();
String ngCtrl = id + "Ctrl";
String ngList = id + "List";
Map<String, Object> values = new HashMap<String, Object>();
values.put("ngCtrl", ngCtrl);
values.put("ngList", ngList);
// use Freemarker to setup an AngularJS/Wicket html snippet
FreemarkerPanel panel = new FreemarkerPanel("listComponent", "FilterableProjectList.fm", values);
panel.setParseGeneratedMarkup(true);
panel.setRenderBodyOnly(true);
add(panel);
// add the Wicket controls that are referenced in the snippet
String listTitle = StringUtils.isEmpty(title) ? getString("gb.projects") : title;
panel.add(new Label(ngList + "Title", MessageFormat.format("{0} ({1})", listTitle, projects.size())));
if (StringUtils.isEmpty(iconClass)) {
panel.add(new Label(ngList + "Icon").setVisible(false));
} else {
Label icon = new Label(ngList + "Icon");
WicketUtils.setCssClass(icon, iconClass);
panel.add(icon);
}
String format = app().settings().getString(Keys.web.datestampShortFormat, "MM/dd/yy");
final DateFormat df = new SimpleDateFormat(format);
df.setTimeZone(getTimeZone());
Collections.sort(projects, new Comparator<ProjectModel>() {
@Override
public int compare(ProjectModel o1, ProjectModel o2) {
return o2.lastChange.compareTo(o1.lastChange);
}
});
List<ProjectListItem> list = new ArrayList<ProjectListItem>();
for (ProjectModel proj : projects) {
if (proj.isUserProject() || proj.repositories.isEmpty()) {
// exclude user projects from list
continue;
}
ProjectListItem item = new ProjectListItem();
item.p = proj.name;
item.n = StringUtils.isEmpty(proj.title) ? proj.name : proj.title;
item.i = proj.description;
item.t = getTimeUtils().timeAgo(proj.lastChange);
item.d = df.format(proj.lastChange);
item.c = proj.repositories.size();
list.add(item);
}
// inject an AngularJS controller with static data
NgController ctrl = new NgController(ngCtrl);
ctrl.addVariable(ngList, list);
add(new HeaderContributor(ctrl));
}
Aggregations