Changeset 5503


Ignore:
Timestamp:
07/31/14 08:55:50 (10 years ago)
Author:
Twan Goosen
Message:

Implemented the admin page, which now has a drop down selector for a "collections space" (published/user) and the same table as the one on the "browse private collections" page
Refs #589

Location:
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/gui
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/gui/pages/AdminPage.html

    r906 r5503  
    11<?xml version="1.0" encoding="UTF-8"?>
    22<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    3                       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     3    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    44<html xmlns="http://www.w3.org/1999/xhtml"
    55      xmlns:wicket="http://wicket.apache.org/">
    6 <head />
    7 <body>
    8 <wicket:extend>
    9   <p style="font-size: 120%; text-align: center;">Admin Page</p>
    10 </wicket:extend>
    11 </body>
     6    <head />
     7    <body>
     8        <wicket:extend>
     9            <h1>VCR administration</h1>
     10            <form wicket:id="spaceSelectForm">
     11                <label for="space">Collections space:</label>
     12                <select id="space" wicket:id="space">
     13                    <option>Public</option>
     14                    <option>User 1</option>
     15                    <option>User 2</option>
     16                </select>
     17                <input type="submit" value="Select" />
     18            </form>
     19            <wicket:container wicket:id="collections">[collections]</wicket:container>
     20        </wicket:extend>
     21    </body>
    1222</html>
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/gui/pages/AdminPage.java

    r5417 r5503  
    11package eu.clarin.cmdi.virtualcollectionregistry.gui.pages;
    22
     3import eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistry;
     4import eu.clarin.cmdi.virtualcollectionregistry.gui.table.AdminCollectionsProvider;
     5import eu.clarin.cmdi.virtualcollectionregistry.model.User;
     6import java.util.ArrayList;
     7import java.util.List;
    38import org.apache.wicket.authorization.strategies.role.Roles;
    49import org.apache.wicket.authorization.strategies.role.annotations.AuthorizeAction;
    510import org.apache.wicket.authorization.strategies.role.annotations.AuthorizeInstantiation;
     11import org.apache.wicket.markup.html.form.DropDownChoice;
     12import org.apache.wicket.markup.html.form.Form;
     13import org.apache.wicket.markup.html.form.IChoiceRenderer;
     14import org.apache.wicket.model.IModel;
     15import org.apache.wicket.model.LoadableDetachableModel;
     16import org.apache.wicket.model.Model;
     17import org.apache.wicket.spring.injection.annot.SpringBean;
    618
     19/**
     20 * Page that allows the admin to select a "space" (public or user private) and
     21 * show all collections in that space with options to edit/delete/publish
     22 *
     23 * @author twagoo
     24 */
    725@AuthorizeInstantiation(Roles.ADMIN)
    8 @AuthorizeAction(action = "ENABLE", roles = { Roles.ADMIN })
     26@AuthorizeAction(action = "ENABLE", roles = {Roles.ADMIN})
    927public class AdminPage extends BasePage {
     28
     29    @SpringBean
     30    private VirtualCollectionRegistry vc;
    1031
    1132    public AdminPage() {
    1233        super();
     34
     35        // user model shared between spaces form and the table's provider
     36        final IModel<User> userModel = new Model<>(null);
     37
     38        // create form that allows admin to select a space
     39        final Form spaceSelectForm = new Form("spaceSelectForm");
     40        final DropDownChoice<User> spacesDropDown = createSpacesDropDown("space", userModel);
     41        spaceSelectForm.add(spacesDropDown);
     42        add(spaceSelectForm);
     43
     44        // create table showing the collections in the space
     45        final AdminCollectionsProvider provider = new AdminCollectionsProvider(userModel);
     46        add(new BrowseEditableCollectionsPanel("collections", provider));
     47    }
     48
     49    private DropDownChoice<User> createSpacesDropDown(String id, final IModel<User> userModel) {
     50        final IModel<List<User>> usersModel = new LoadableDetachableModel<List<User>>() {
     51
     52            @Override
     53            protected List<User> load() {
     54                final List<User> users = vc.getUsers();
     55
     56                // merge with a 'null' entry to represent the public space
     57                final List<User> spaces = new ArrayList<>(users.size() + 1);
     58                spaces.add(null);
     59                spaces.addAll(users);
     60                return spaces;
     61            }
     62        };
     63        final IChoiceRenderer<User> choiceRenderer = new IChoiceRenderer<User>() {
     64
     65            @Override
     66            public Object getDisplayValue(User user) {
     67                if (user == null) {
     68                    return "Published profiles";
     69                } else {
     70                    final String displayName = user.getDisplayName();
     71                    if (displayName == null) {
     72                        return user.getName();
     73                    } else {
     74                        return displayName;
     75                    }
     76                }
     77            }
     78
     79            @Override
     80            public String getIdValue(User user, int index) {
     81                if (user == null) {
     82                    return "___PUBLIC___";
     83                } else {
     84                    return user.getName();
     85                }
     86            }
     87        };
     88        final DropDownChoice<User> spacesDropDown = new DropDownChoice<>(id, userModel, usersModel, choiceRenderer);
     89        spacesDropDown.setNullValid(true);
     90        return spacesDropDown;
    1391    }
    1492
Note: See TracChangeset for help on using the changeset viewer.