Search in sources :

Example 1 with CommentThreadObjectTypeManager

use of com.helger.peppol.comment.domain.CommentThreadObjectTypeManager in project peppol-practical by phax.

the class PageSecureCommentAdmin method fillContent.

@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final CommentThreadManager aCommentThreadMgr = CommentThreadManager.getInstance();
    boolean bShowList = true;
    final String sSelectedObjectType = aWPEC.params().getAsString(PARAM_TYPE);
    final String sSelectedOwningObjectID = aWPEC.params().getAsString(CPageParam.PARAM_OBJECT);
    if (aWPEC.hasAction(CPageParam.ACTION_VIEW) && StringHelper.hasText(sSelectedObjectType) && StringHelper.hasText(sSelectedOwningObjectID)) {
        final TypedObject<String> aTO = TypedObject.create(new ObjectType(sSelectedObjectType), sSelectedOwningObjectID);
        final List<ICommentThread> aCommentThreads = aCommentThreadMgr.getAllCommentThreadsOfObject(aTO);
        if (!aCommentThreads.isEmpty()) {
            // Don't allow comment creation
            aNodeList.addChild(CommentUI.getCommentList(aWPEC, aTO, CommentAction.createGeneric(ECommentAction.NONE), null, null, false));
            // Toolbar
            final IButtonToolbar<?> aToolbar = new BootstrapButtonToolbar(aWPEC);
            aToolbar.addButton(EPhotonCoreText.BACK_TO_OVERVIEW.getDisplayText(aDisplayLocale), aWPEC.getSelfHref(), EDefaultIcon.BACK_TO_LIST);
            aNodeList.addChild(aToolbar);
            bShowList = false;
        }
    }
    if (bShowList) {
        // Refresh button
        final IButtonToolbar<?> aToolbar = new BootstrapButtonToolbar(aWPEC);
        aToolbar.addButton(EPhotonCoreText.BUTTON_REFRESH.getDisplayText(aDisplayLocale), aWPEC.getSelfHref(), EDefaultIcon.REFRESH);
        aNodeList.addChild(aToolbar);
        final ITabBox<?> aTabBox = new BootstrapTabBox();
        for (final ObjectType aOT : CollectionHelper.getSorted(aCommentThreadMgr.getAllRegisteredObjectTypes())) {
            final HCNodeList aTab = new HCNodeList();
            final HCTable aTable = new HCTable(new DTCol(EText.HEADER_OBJECT_ID.getDisplayText(aDisplayLocale)), new DTCol(EText.HEADER_THREADS.getDisplayText(aDisplayLocale)).addClass(CSS_CLASS_RIGHT).setDisplayType(EDTColType.INT, aDisplayLocale), new DTCol(EText.HEADER_COMMENTS.getDisplayText(aDisplayLocale)).addClass(CSS_CLASS_RIGHT).setDisplayType(EDTColType.INT, aDisplayLocale), new DTCol(EText.HEADER_ACTIVE_COMMENTS.getDisplayText(aDisplayLocale)).addClass(CSS_CLASS_RIGHT).setDisplayType(EDTColType.INT, aDisplayLocale), new DTCol(EText.HEADER_LAST_CHANGE.getDisplayText(aDisplayLocale)).addClass(CSS_CLASS_RIGHT).setDisplayType(EDTColType.DATETIME, aDisplayLocale).setInitialSorting(ESortOrder.DESCENDING)).setID(getID() + aOT.getName());
            final CommentThreadObjectTypeManager aCTOTMgr = aCommentThreadMgr.getManagerOfObjectType(aOT);
            for (final Map.Entry<String, ICommonsList<ICommentThread>> aEntry : aCTOTMgr.getAllCommentThreads().entrySet()) {
                final String sOwningObjectID = aEntry.getKey();
                final ISimpleURL aViewURL = AbstractWebPageForm.createViewURL(aWPEC, sOwningObjectID).add(PARAM_TYPE, aOT.getName());
                final HCRow aRow = aTable.addBodyRow();
                aRow.addCell(new HCA(aViewURL).addChild(sOwningObjectID));
                aRow.addCell(Integer.toString(aEntry.getValue().size()));
                int nActiveComments = 0;
                final ICommonsList<IComment> aAllComments = new CommonsArrayList<>();
                for (final ICommentThread aCommentThread : aEntry.getValue()) {
                    aAllComments.addAll(aCommentThread.getAllComments());
                    nActiveComments += aCommentThread.getTotalActiveCommentCount();
                }
                Collections.sort(aAllComments, Comparator.comparing(IComment::getLastChangeDateTime).reversed());
                aRow.addCell(Integer.toString(aAllComments.size()));
                aRow.addCell(Integer.toString(nActiveComments));
                if (aAllComments.isEmpty())
                    aRow.addCell();
                else
                    aRow.addCell(PDTToString.getAsString(aAllComments.get(0).getLastChangeDateTime(), aDisplayLocale));
            }
            aTab.addChild(aTable);
            final DataTables aDataTables = BootstrapDataTables.createDefaultDataTables(aWPEC, aTable);
            aTab.addChild(aDataTables);
            aTabBox.addTab(aOT.getName(), aOT.getName(), aTab, aOT.getName().equals(sSelectedObjectType));
        }
        aNodeList.addChild(aTabBox);
    }
}
Also used : Locale(java.util.Locale) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IComment(com.helger.peppol.comment.domain.IComment) HCNodeList(com.helger.html.hc.impl.HCNodeList) HCRow(com.helger.html.hc.html.tabular.HCRow) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapTabBox(com.helger.photon.bootstrap4.nav.BootstrapTabBox) ICommentThread(com.helger.peppol.comment.domain.ICommentThread) ObjectType(com.helger.commons.type.ObjectType) CommentThreadObjectTypeManager(com.helger.peppol.comment.domain.CommentThreadObjectTypeManager) ISimpleURL(com.helger.commons.url.ISimpleURL) CommentThreadManager(com.helger.peppol.comment.domain.CommentThreadManager) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) DataTables(com.helger.photon.uictrls.datatables.DataTables) BootstrapDataTables(com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables) HCA(com.helger.html.hc.html.textlevel.HCA) HCTable(com.helger.html.hc.html.tabular.HCTable) DTCol(com.helger.photon.uictrls.datatables.column.DTCol) Map(java.util.Map) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList)

Aggregations

CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 ICommonsList (com.helger.commons.collection.impl.ICommonsList)1 PDTToString (com.helger.commons.datetime.PDTToString)1 ObjectType (com.helger.commons.type.ObjectType)1 ISimpleURL (com.helger.commons.url.ISimpleURL)1 HCRow (com.helger.html.hc.html.tabular.HCRow)1 HCTable (com.helger.html.hc.html.tabular.HCTable)1 HCA (com.helger.html.hc.html.textlevel.HCA)1 HCNodeList (com.helger.html.hc.impl.HCNodeList)1 CommentThreadManager (com.helger.peppol.comment.domain.CommentThreadManager)1 CommentThreadObjectTypeManager (com.helger.peppol.comment.domain.CommentThreadObjectTypeManager)1 IComment (com.helger.peppol.comment.domain.IComment)1 ICommentThread (com.helger.peppol.comment.domain.ICommentThread)1 BootstrapButtonToolbar (com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar)1 BootstrapTabBox (com.helger.photon.bootstrap4.nav.BootstrapTabBox)1 BootstrapDataTables (com.helger.photon.bootstrap4.uictrls.datatables.BootstrapDataTables)1 DataTables (com.helger.photon.uictrls.datatables.DataTables)1 DTCol (com.helger.photon.uictrls.datatables.column.DTCol)1 Locale (java.util.Locale)1 Map (java.util.Map)1