Skip to content

DocToValidate Extension

Valentin Rigolle edited this page May 13, 2019 · 2 revisions

DocToValidate Extension

The DocToValidate extension is meant to access the ExtendedDocToValidate, comment, update and validate them.

Existing functionnalities

The current version of the extension allows any user to search and view documents.

The extensions has two main components : the view and the service. The service performs the basic requests about documents and stores them. The view consists of two movable windows : a search window and a document viewer. Both are movable and resizable.

Basic usage

The DocToValidate extension requires a RequestService in order to perform requests, and a config object to specify the backend API routes. The config object must be a dict object containing at least the following structure :

{
    server:{
      url:'http://localhost:5000/',
      documentsToValidate:'document/in_validation',
      document:'document',
      validate:'document/validate',
      user:'user',
      file:'file',
      comment:'comment'
    }
}

An example of a valid config file can be found here.

To properly instanciate the module, you need to first create the service and then the view.

const docToValidateService = new udvcore.DocToValidateService(requestService, config);
const docToValidateView = new udvcore.DocToValidateView(docToValidateService);

Then you can simply add a toggle button in your app, to show and hide the view :

document.getElementById('docToValidateToggle').onclick = () => {
    if (docToValidateView.isVisible()) {
        docToValidateView.dispose();
    } else {
        docToValidateView.appendToElement(document.getElementById('contentSection'));
    }
}

View

The view consists of three classes : a global DocToValidateView, which serves as a wrapper for the three windows of the module, the DocToValidateSearchWindow, the DocToValidateBrowserWindow and the DocToValidateCommentWindow. The three windows use the DocToValidateService to call services or retrieve displayable data. All three implement the Window framework described here.

The styles are defined in a specific CSS file, called DocToValidateStyle.css. It contains the styles for the content of the windows. If you want to change how the module looks, you might want to check that.

Service

The service has three functions.

First, it performs the requests upon the server to get documents. The preferred way of doing so is through the search method, which takes a FormData as a parameter containing the filters for the documents. The form data can contain the following fields (all of them are optional. Is no field is specified, all of the documents are retrieved) :

Key Description
keyword Filters the documents so that only those whose title containes the keyword are kept.
startReferringDate Only keeps the document with a referring date greater than this value.
endReferringDate Only keeps the document with a referring date smaller than this value.
startPublicationDate Only keeps the document with a publication date greater than this value.
endPublicationDate Only keeps the document with a publication date smaller than this value.

Then, it exposes access methods to act on the retreived documents. The specificity of the service is that you can only see one document at a time. It actually stores a list of documents when the search method is called, but not all data (especially the associated filed) is loaded. It can only be accessed through the prevDocument(), nextDocument() and currentDocument() methods.

Method Description
getDocuments() Retrieve an array containing all the documents stored in the service. It doesn't perform any fetch request, so the informations in this array are not complete.
getDocumentsCount() Returns the size of the documents array. Simpler way than getDocuments().length
getCurrentDocument() Returns full information about the current document.
getCurrentDocumentId() Returns the position of the current position in the documents array. Position is an integer starting at 0.
nextDocument() Moves the current document position right in the documents array, and retrieves this document. If the end of the array is reached, it starts again at the beginning.
prevDocument() Moves the current document position left in the documents array, and retrieves this document. If the beginning of the array is reached, it continues from the end.

Finally, the service sends notifications to inform potential listeners of the document changes. For that purpose it uses a simple observer system.

Method Description
addObserver(observer) Register the observer in the service. The parameter must be a function without argument.
notifyObservers() Sends a notification to all observers. This is simply done by calling all the observers that were passed through the addObserver method.