Package com.psddev.dari.db

Examples of com.psddev.dari.db.State


        if (type != null || userType != UserType.ANYONE) {
            queryFilter = new QueryFilter<Object>() {

                @Override
                public boolean include(Object item) {
                    State itemState = State.getInstance(item);
                    boolean typeOk = true;
                    boolean userOk = true;

                    if (type != null) {
                        ObjectType itemType = item instanceof Draft ? ((Draft) item).getObjectType() : itemState.getType();
                        typeOk = itemType != null && itemType.getGroups().contains(type.getInternalName());
                    }

                    if (userType != UserType.ANYONE) {
                        ToolUser updateUser = itemState.as(Content.ObjectModification.class).getUpdateUser();

                        if (userType == UserType.ME) {
                            userOk = page.getUser().equals(updateUser);

                        } else if (user instanceof ToolUser) {
                            userOk = user.equals(updateUser);

                        } else if (user instanceof ToolRole && updateUser != null) {
                            userOk = user.equals(updateUser.getRole());
                        }
                    }

                    return typeOk && userOk;
                }
            };
        }

        int limit = page.pageParam(int.class, "limit", 20);
        PaginatedResult<?> drafts = draftsQuery.
                and("* matches *").
                and(Content.UPDATE_DATE_FIELD + " != missing").
                and(page.siteItemsPredicate()).
                sortDescending(Content.UPDATE_DATE_FIELD).
                selectFiltered(page.param(long.class, "offset"), limit, queryFilter);

        page.writeStart("div", "class", "widget widget-unpublishedDrafts");
            page.writeStart("h1", "class", "icon icon-object-draft");
                page.writeHtml("Unpublished Drafts");
            page.writeEnd();

            page.writeStart("form",
                    "method", "get",
                    "action", page.url(null));
                page.writeStart("ul", "class", "oneLine");
                    if (workflowStateLabels.size() > 1) {
                        page.writeStart("li");
                            page.writeStart("select",
                                    "data-bsp-autosubmit", "",
                                    "name", "state");
                                page.writeStart("option", "value", "");
                                    page.writeHtml("Any Statuses");
                                page.writeEnd();

                                for (Map.Entry<String, String> entry : workflowStateLabels.entrySet()) {
                                    String key = entry.getKey();

                                    page.writeStart("option",
                                            "selected", key.equals(state) ? "selected" : null,
                                            "value", key);
                                        page.writeHtml(entry.getValue());
                                    page.writeEnd();
                                }
                            page.writeEnd();
                        page.writeEnd();
                    }

                    page.writeStart("li");
                        page.writeTypeSelect(
                                ObjectType.getInstance(Content.class).as(ToolUi.class).findDisplayTypes(),
                                type,
                                "Any Types",
                                "name", "typeId",
                                "data-bsp-autosubmit", "",
                                "data-searchable", true);
                    page.writeEnd();

                    page.writeStart("li");
                        page.writeHtml("by ");
                        page.writeStart("select",
                                "data-bsp-autosubmit", "",
                                "name", "userType");
                            for (UserType t : UserType.values()) {
                                if (t != UserType.ROLE || Query.from(ToolRole.class).first() != null) {
                                    page.writeStart("option",
                                            "selected", t.equals(userType) ? "selected" : null,
                                            "value", t.name());
                                        page.writeHtml(t.getDisplayName());
                                    page.writeEnd();
                                }
                            }
                        page.writeEnd();

                        page.writeHtml(" ");

                        Query<?> userQuery;

                        if (userType == UserType.ROLE) {
                            userQuery = Query.from(ToolRole.class).sortAscending("name");

                        } else if (userType == UserType.USER) {
                            userQuery = Query.from(ToolUser.class).sortAscending("name");

                        } else {
                            userQuery = null;
                        }

                        if (userQuery != null) {
                            if (userQuery.hasMoreThan(250)) {
                                State userState = State.getInstance(user);

                                page.writeElement("input",
                                        "type", "text",
                                        "class", "objectId",
                                        "data-bsp-autosubmit", "",
                                        "data-editable", false,
                                        "data-label", userState != null ? userState.getLabel() : null,
                                        "data-typeIds", ObjectType.getInstance(ToolRole.class).getId(),
                                        "name", userParameter,
                                        "value", userState != null ? userState.getId() : null);

                            } else {
                                page.writeStart("select",
                                        "name", userParameter,
                                        "data-bsp-autosubmit", "",
                                        "data-searchable", "true");
                                    page.writeStart("option", "value", "").writeEnd();

                                    for (Object v : userQuery.selectAll()) {
                                        State userState = State.getInstance(v);

                                        page.writeStart("option",
                                                "value", userState.getId(),
                                                "selected", v.equals(user) ? "selected" : null);
                                            page.writeHtml(userState.getLabel());
                                        page.writeEnd();
                                    }
                                page.writeEnd();
                            }
                        }
                    page.writeEnd();
                page.writeEnd();
            page.writeEnd();

            if (drafts.getItems().isEmpty()) {
                String label = state != null ? workflowStateLabels.get(state) : null;

                page.writeStart("div", "class", "message message-info");
                    page.writeHtml("No ");
                    page.writeHtml(label != null ? label.toLowerCase(Locale.ENGLISH) : "matching");
                    page.writeHtml(" items.");
                page.writeEnd();

            } else {
                page.writeStart("ul", "class", "pagination");
                    if (drafts.hasPrevious()) {
                        page.writeStart("li", "class", "first");
                            page.writeStart("a", "href", page.url("", "offset", drafts.getFirstOffset()));
                                page.writeHtml("Newest");
                            page.writeEnd();
                        page.writeEnd();

                        page.writeStart("li", "class", "previous");
                            page.writeStart("a", "href", page.url("", "offset", drafts.getPreviousOffset()));
                                page.writeHtml("Newer ");
                                page.writeHtml(drafts.getLimit());
                            page.writeEnd();
                        page.writeEnd();
                    }

                    page.writeStart("li");
                        page.writeStart("form",
                                "data-bsp-autosubmit", "",
                                "method", "get",
                                "action", page.url(null));
                            page.writeStart("select", "name", "limit");
                                for (int l : LIMITS) {
                                    page.writeStart("option",
                                            "value", l,
                                            "selected", limit == l ? "selected" : null);
                                        page.writeHtml("Show ");
                                        page.writeHtml(l);
                                    page.writeEnd();
                                }
                            page.writeEnd();
                        page.writeEnd();
                    page.writeEnd();

                    if (drafts.hasNext()) {
                        page.writeStart("li", "class", "next");
                            page.writeStart("a", "href", page.url("", "offset", drafts.getNextOffset()));
                                page.writeHtml("Older ");
                                page.writeHtml(drafts.getLimit());
                            page.writeEnd();
                        page.writeEnd();
                    }
                page.writeEnd();

                page.writeStart("table", "class", "links table-striped pageThumbnails");
                    page.writeStart("tbody");
                        for (Object item : drafts.getItems()) {
                            if (item instanceof Draft) {
                                Draft draft = (Draft) item;
                                item = draft.getObject();

                                if (item == null) {
                                    continue;
                                }

                                State itemState = State.getInstance(item);

                                if (!itemState.isVisible() &&
                                        draft.getObjectChanges().isEmpty()) {
                                    continue;
                                }

                                UUID draftId = draft.getId();

                                page.writeStart("tr", "data-preview-url", "/_preview?_cms.db.previewId=" + draftId);
                                    page.writeStart("td");
                                        page.writeStart("span", "class", "visibilityLabel");
                                            page.writeHtml("Update");
                                        page.writeEnd();
                                    page.writeEnd();

                                    page.writeStart("td");
                                        page.writeHtml(page.getTypeLabel(item));
                                    page.writeEnd();

                                    page.writeStart("td", "data-preview-anchor", "");
                                        page.writeStart("a",
                                                "target", "_top",
                                                "href", page.url("/content/edit.jsp",
                                                        "id", itemState.getId(),
                                                        "draftId", draftId));
                                            page.writeHtml(itemState.getLabel());
                                        page.writeEnd();
                                    page.writeEnd();

                                    page.writeStart("td");
                                        page.writeObjectLabel(draft.as(Content.ObjectModification.class).getUpdateUser());
                                    page.writeEnd();
                                page.writeEnd();

                            } else {
                                State itemState = State.getInstance(item);
                                UUID itemId = itemState.getId();

                                page.writeStart("tr", "data-preview-url", "/_preview?_cms.db.previewId=" + itemId);
                                    page.writeStart("td");
                                        page.writeStart("span", "class", "visibilityLabel");
                                            page.writeHtml(itemState.getVisibilityLabel());
                                        page.writeEnd();
                                    page.writeEnd();

                                    page.writeStart("td");
                                        page.writeHtml(page.getTypeLabel(item));
                                    page.writeEnd();

                                    page.writeStart("td", "data-preview-anchor", "");
                                        page.writeStart("a", "href", page.url("/content/edit.jsp", "id", itemId), "target", "_top");
                                            page.writeHtml(itemState.getLabel());
                                        page.writeEnd();
                                    page.writeEnd();

                                    page.writeStart("td");
                                        page.writeObjectLabel(itemState.as(Content.ObjectModification.class).getUpdateUser());
                                    page.writeEnd();
                                page.writeEnd();
                            }
                        }
                    page.writeEnd();
View Full Code Here


            @Override
            public void renderBeforeItem(Object item) throws IOException {
                Reference enhancement = new Reference();
                RichTextReference rt = enhancement.as(RichTextReference.class);
                State state = State.getInstance(item);

                enhancement.setObject(item);
                rt.setLabel(state.getLabel());
                rt.setPreview(page.getPreviewThumbnailUrl(item));

                page.writeStart("a",
                        "data-enhancement", ObjectUtils.toJson(enhancement.getState().getSimpleValues()),
                        "href", "#");
View Full Code Here

        return null;
    }

    @Override
    protected void doService(final ToolPageContext page) throws IOException, ServletException {
        State state = State.getInstance(Query.from(Object.class).where("_id = ?", page.param(UUID.class, "id")).first());
        ColorDistribution distribution = state.as(ColorDistribution.Data.class).getDistribution();

        if (distribution == null) {
            return;
        }
View Full Code Here

                        if (valueQuery == null) {
                            page.writeHtml("\u0020");

                        } else {
                            if (valueQuery.hasMoreThan(250)) {
                                State valueState = State.getInstance(valueObject);

                                page.writeElement("input",
                                        "data-bsp-autosubmit", "",
                                        "type", "text",
                                        "class", "objectId",
                                        "data-editable", false,
                                        "data-label", valueState != null ? valueState.getLabel() : null,
                                        "data-typeIds", ObjectType.getInstance(ToolRole.class).getId(),
                                        "name", valueParameter,
                                        "value", valueState != null ? valueState.getId() : null);

                            } else {
                                page.writeStart("select",
                                        "data-bsp-autosubmit", "",
                                        "name", valueParameter,
                                        "data-searchable", "true");

                                    page.writeStart("option", "value", "").writeEnd();

                                    for (Object v : valueQuery.selectAll()) {
                                        State state = State.getInstance(v);

                                        page.writeStart("option",
                                                "value", state.getId(),
                                                "selected", v.equals(valueObject) ? "selected" : null);
                                            page.writeHtml(state.getLabel());
                                        page.writeEnd();
                                    }

                                page.writeEnd();
                            }
                        }
                    page.writeEnd();

                    page.writeStart("li");
                        page.writeTag("input", "type", "hidden", "name", Search.VISIBILITIES_PARAMETER, "value", ""); // extra hidden field so ToolPageContext#pageParams() knows we are intentionally submitting nothing
                        page.writeMultipleVisibilitySelect(itemType, visibilities, "name", Search.VISIBILITIES_PARAMETER, "data-bsp-autosubmit", "");
                    page.writeEnd();

                page.writeEnd();
            page.writeEnd();

            if (result == null) {
                page.writeStart("div", "class", "message message-warning");
                    page.writeStart("p");
                        page.writeHtml("Please select a ");
                        page.writeHtml(type.getDisplayName());
                        page.writeHtml(".");
                    page.writeEnd();
                page.writeEnd();

            } else if (!result.hasPages()) {
                page.writeStart("div", "class", "message message-info");
                    page.writeStart("p");
                        page.writeHtml("No recent activity!");
                    page.writeEnd();
                page.writeEnd();

            } else {
                page.writeStart("ul", "class", "pagination");

                    if (result.hasPrevious()) {
                        page.writeStart("li", "class", "first");
                            page.writeStart("a",
                                    "href", page.url("", "offset", result.getFirstOffset()));
                                page.writeHtml("Newest");
                            page.writeEnd();
                        page.writeEnd();

                        page.writeStart("li", "class", "previous");
                            page.writeStart("a",
                                    "href", page.url("", "offset", result.getPreviousOffset()));
                                page.writeHtml("Newer ").writeHtml(limit);
                            page.writeEnd();
                        page.writeEnd();
                    }

                    if (result.getOffset() > 0 ||
                            result.hasNext() ||
                            result.getItems().size() > LIMITS[0]) {
                        page.writeStart("li");
                            page.writeStart("form",
                                    "data-bsp-autosubmit", "",
                                    "method", "get",
                                    "action", page.url(null));
                                page.writeStart("select", "name", "limit");
                                    for (int l : LIMITS) {
                                        page.writeStart("option",
                                                "value", l,
                                                "selected", limit == l ? "selected" : null);
                                            page.writeHtml("Show ");
                                            page.writeHtml(l);
                                        page.writeEnd();
                                    }
                                page.writeEnd();
                            page.writeEnd();
                        page.writeEnd();
                    }

                    if (result.hasNext()) {
                        page.writeStart("li", "class", "next");
                            page.writeStart("a",
                                    "href", page.url("", "offset", result.getNextOffset()));
                                page.writeHtml("Older ").writeHtml(limit);
                            page.writeEnd();
                        page.writeEnd();
                    }

                page.writeEnd();

                page.writeStart("table", "class", "links table-striped pageThumbnails").writeStart("tbody");

                    String lastUpdateDate = null;

                    for (Object content : result.getItems()) {
                        State contentState = State.getInstance(content);
                        String permalink = contentState.as(Directory.ObjectModification.class).getPermalink();
                        Content.ObjectModification contentData = contentState.as(Content.ObjectModification.class);
                        DateTime updateDateTime = page.toUserDateTime(contentData.getUpdateDate());
                        String updateDate = page.formatUserDate(updateDateTime);
                        ToolUser updateUser = contentData.getUpdateUser();

                        page.writeStart("tr", "data-preview-url", permalink);
View Full Code Here

            if (isOverlay()) {
                StorageItem item = null;
                Map<String, ImageCrop> crops = null;

                if (this.state != null) {
                    State objectState = this.state;
                    String field = this.field;

                    if (ObjectUtils.isBlank(field)) {
                        field = findStorageItemField(objectState);
                    }
View Full Code Here

            Integer originalWidth = null;
            Integer originalHeight = null;
            Map<String, ImageCrop> crops = null;

            if (this.state != null) { // backwards compatibility path
                State objectState = this.state;
                String field = this.field;

                if (ObjectUtils.isBlank(field)) {
                    field = findStorageItemField(objectState);
                }
View Full Code Here

                                if (!type.equals(URL_TYPE)) {
                                    page.writeStart("option", "value", "").writeEnd();
                                }

                                for (Object v : valueQuery.selectAll()) {
                                    State state = State.getInstance(v);

                                    page.writeStart("option",
                                            "value", state.getId(),
                                            "selected", v.equals(valueObject) ? "selected" : null);
                                        page.writeHtml(state.getLabel());
                                    page.writeEnd();
                                }

                            page.writeEnd();
                        }
                    page.writeEnd();
                page.writeEnd();
            page.writeEnd();

            if (valueObject == null) {
                page.writeStart("div", "class", "message message-warning");
                    page.writeStart("p");
                        page.writeHtml("Please select a ");
                        page.writeStart("strong").writeHtml(valueType.getLabel()).writeEnd();
                        page.writeHtml(".");
                    page.writeEnd();
                page.writeEnd();

            } else if (!result.hasPages()) {
                page.writeStart("div", "class", "message message-info");
                    page.writeStart("p");
                        page.writeHtml("No ");

                        if (itemType == null) {
                            page.writeHtml("items");

                        } else {
                            page.writeStart("strong");
                                page.writeObjectLabel(itemType);
                            page.writeEnd();
                        }

                        page.writeHtml(" matching ");
                        page.writeStart("strong");
                            page.writeObjectLabel(valueObject);
                        page.writeEnd();
                        page.writeHtml(".");
                    page.writeEnd();
                page.writeEnd();

            } else {
                page.writeStart("ul", "class", "pagination");

                    if (result.hasPrevious()) {
                        page.writeStart("li", "class", "first");
                            page.writeStart("a", "href", page.url("", "offset", result.getFirstOffset())).writeHtml("First").writeEnd();
                        page.writeEnd();

                        page.writeStart("li", "class", "previous");
                            page.writeStart("a", "href", page.url("", "offset", result.getPreviousOffset())).writeHtml("Previous ").writeHtml(result.getLimit()).writeEnd();
                        page.writeEnd();
                    }

                    if (result.getOffset() > 0 ||
                            result.hasNext() ||
                            result.getItems().size() > LIMITS[0]) {
                        page.writeStart("li");
                            page.writeStart("form",
                                    "data-bsp-autosubmit", "",
                                    "method", "get",
                                    "action", page.url(null));
                                page.writeStart("select", "name", "limit");
                                    for (int l : LIMITS) {
                                        page.writeStart("option",
                                                "value", l,
                                                "selected", limit == l ? "selected" : null);
                                            page.writeHtml("Show ");
                                            page.writeHtml(l);
                                        page.writeEnd();
                                    }
                                page.writeEnd();
                            page.writeEnd();
                        page.writeEnd();
                    }

                    if (count != null) {
                        page.writeStart("li");
                            page.writeHtml(result.getFirstItemIndex());
                            page.writeHtml(" to ");
                            page.writeHtml(result.getLastItemIndex());
                            page.writeHtml(" of ");
                            page.writeStart("strong").writeHtml(count).writeEnd();
                        page.writeEnd();
                    }

                    if (result.hasNext()) {
                        page.writeStart("li", "class", "next");
                            page.writeStart("a", "href", page.url("", "offset", result.getNextOffset())).writeHtml("Next ").writeHtml(result.getLimit()).writeEnd();
                        page.writeEnd();
                    }

                page.writeEnd();

                page.writeStart("table", "class", "links pageThumbnails table-striped");
                    page.writeStart("tbody");

                        for (Object item : result.getItems()) {
                            State itemState = State.getInstance(item);
                            String permalink = null;

                            if (type.equals(URL_TYPE)) {
                                for (Directory.Path pathObject : itemState.as(Directory.ObjectModification.class).getPaths()) {
                                    String p = pathObject.getPath();

                                    if (StringUtils.getPathInfo(p, ((Directory) valueObject).getPath()) != null) {
                                        permalink = p;
                                        break;
                                    }
                                }

                            } else {
                                permalink = itemState.as(Directory.ObjectModification.class).getPermalink();
                            }

                            page.writeStart("tr", "data-preview-url", permalink);

                                page.writeStart("td");
View Full Code Here

    }

    // Synchronizes the given {@code plugin} with the existing one in the
    // database if it can be found.
    private void synchronizePlugin(Plugin plugin) {
        State pluginState = plugin.getState();
        Database database = getState().getDatabase();

        pluginState.setDatabase(database);

        UUID typeId = pluginState.getTypeId();
        Tool tool = plugin.getTool();
        String internalName = plugin.getInternalName();

        for (Plugin p : Static.getPlugins()) {
            if (ObjectUtils.equals(typeId, p.getState().getTypeId()) &&
                    ObjectUtils.equals(tool, p.getTool()) &&
                    ObjectUtils.equals(internalName, p.getInternalName())) {
                pluginState.setId(p.getId());
                break;
            }
        }
    }
View Full Code Here

        if (!page.isFormPost()) {
            throw new IllegalStateException("Form must be posted!");
        }

        ToolUser user = page.getUser();
        State userState = user.getState();

        for (String action : page.params(String.class, "action")) {
            if ("liveContentPreview-enable".equals(action)) {
                userState.put("liveContentPreview", true);

            } else if ("liveContentPreview-disable".equals(action)) {
                userState.put("liveContentPreview", false);

            } else if ("dashboardWidgets-position".equals(action)) {
                userState.put("dashboardWidgets", ObjectUtils.fromJson(page.param(String.class, "widgets")));
                userState.put("dashboardWidgetsCollapse", ObjectUtils.fromJson(page.param(String.class, "widgetsCollapse")));

            } else if ("scheduleSet".equals(action)) {
                user.setCurrentSchedule(Query.
                        from(Schedule.class).
                        where("_id = ?", page.param(UUID.class, "scheduleId")).
                        first());
            }
        }

        userState.save();

        String returnUrl = page.param(String.class, "returnUrl");

        if (!ObjectUtils.isBlank(returnUrl)) {
            page.getResponse().sendRedirect(returnUrl);
View Full Code Here

        renderer.render();

        String pageId = page.createId();
        Query<?> query = search.toQuery(page.getSite());
        State queryState = query.getState();

        queryState.put("cms.ui.search", search.getState().getSimpleValues());

        page.writeStart("div", "id", pageId);
        page.writeEnd();

        page.writeStart("script", "type", "text/javascript");
            page.writeRaw("var $page = $('#").writeRaw(pageId).writeRaw("'),");
                    page.writeRaw("$frame = $page.closest('.queryField_frames > .frame'),");
                    page.writeRaw("$field = $.data($frame[0], 'query-$field'),");
                    page.writeRaw("$input = $field.find('input');");

            page.writeRaw("$input.val('");
            page.writeRaw(page.js(ObjectUtils.toJson(queryState.getSimpleValues())));
            page.writeRaw("');");

            page.writeRaw("$input.change();");
        page.writeEnd();
    }
View Full Code Here

TOP

Related Classes of com.psddev.dari.db.State

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.