close

Filter

loading table of contents...

Studio Developer Manual / Version 2301

Table Of Contents

9.17.5 Customizing the Start-up Behavior

After successful login, Studio restores the tabs of the last session. This default behavior can be disabled by calling the setDefaultTabStateManagerEnabled(enable) method of the singleton @coremedia/studio-client.main.editor-components/sdk/editorContext.

When you set this value to false, Studio will start with a blank working area (that is, no documents or other tabs are open). This might be handy if you want to customize the startup behavior. When, for example, you want to open all documents that a given search query finds on startup, you can do that with code like the following (a plugin attached to the EditorMainView):

import Config from "@jangaroo/runtime/Config";
import StringUtil from "@jangaroo/ext-ts/String";
import Component from "@jangaroo/ext-ts/Component";
import Container from "@jangaroo/ext-ts/container/Container";
import AbstractPlugin from "@jangaroo/ext-ts/plugin/Abstract";
import PropertyChangeEvent from "@coremedia/studio-client.client-core/data/PropertyChangeEvent";
import session from "@coremedia/studio-client.cap-rest-client/common/session";
import SearchParameters from "@coremedia/studio-client.cap-rest-client/content/search/SearchParameters";
import editorContext from "@coremedia/studio-client.main.editor-components/sdk/editorContext";
import MessageBoxUtil from "@coremedia/studio-client.main.editor-components/sdk/util/MessageBoxUtil";
import EditorErrors_properties
  from "@coremedia/studio-client.ext.errors-validation-components/error/EditorErrors_properties";

class OpenCheckedOutDocumentsPlugin extends AbstractPlugin {
  readonly MAX_OPEN_TABS: int = 10;

  constructor(config: Config<AbstractPlugin>) {
    super(config);
  }

  init(component: Component): void {
    //get the top level container
    const mainView = component.findParentBy((container: Container) => {
      return !container.ownerCt;
    });

    mainView.on('afterrender', this.#openDocuments, null, {
      single: true
    });
  }

  #openDocuments(): void {
    // Perform query to determine documents checked out by me.
    const searchParameters = this.#createSearchParameters();
    const searchResult = session._.getConnection().getContentRepository().getSearchService().search(searchParameters);
    // When the query result is loaded ...
    searchResult.addPropertyChangeListener(SearchParameters.HITS,
      (event: PropertyChangeEvent) => {
        // ... open all documents in tabs.
        const searchResult = event.newValue;
        if (searchResult && searchResult.length > 0) {
          editorContext._.getContentTabManager().openDocuments(
            searchResult.slice(0, OpenCheckedOutDocumentsPlugin.MAX_OPEN_TABS));
          if (searchResult.length > OpenCheckedOutDocumentsPlugin.MAX_OPEN_TABS) {
            MessageBoxUtil.showInfo(
              EditorErrors_properties.editorStart_tooManyDocuments_title,
              EditorErrors_properties.editorStart_tooManyDocuments_message
            );
          }
        }
      });
    searchResult.getHits();
  }

  #createSearchParameters(): SearchParameters {
    const searchParameters = new SearchParameters();
    searchParameters.filterQuery = [this.#getQueryFilterString()];

    //searchParameters.contentType = ['Document_'];
    searchParameters.orderBy = ['freshness asc'];

    return searchParameters;
  }

  #getQueryFilterString(): String {
    const filterQueries = [];

    // retrieve user URI for parametrized filter expressions:
    const user = session._.getUser();
    const userUri = "<" + user.getUriPath() + ">";

    // filter documents checked out by me
    filterQueries.push("ischeckedout:true");
    filterQueries.push(StringUtil.format("editor:{0}", userUri));

    return filterQueries.join(" AND ");
  }
}

export default OpenCheckedOutDocumentsPlugin;

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.