Module: reviewController

The controller handles the logic related to adding and removing annotations. It also handles the way how the selected area is defined in the view. Requires velpSelection directive.

Author:
  • Joonas Lattu
  • Petteri Palojärvi
  • Seppo Tarvainen
Source:

Methods

(inner) addAnnotationToCoord(range, annotation, show)

Adds an annotation to the given element in a given coordinate.

Parameters:
Name Type Description
range

Annotation coordinate

annotation

Annotation info

show

Whether annotation is shown when created or not

Source:

(inner) addAnnotationToElement(el, annotation, show, reason)

Adds an annotation to the given element. The annotation will be placed in the margin.

Parameters:
Name Type Description
el

Given element

annotation

Annotation info

show

Whether annotation is shown when created or not

reason

The reason why the annotation is put here (not implemented yet)

Source:

(inner) addComment(id, name, comment)

Adds a comment to the given annotation.

Parameters:
Name Type Description
id

Annotation ID

name

Commenter name

comment

Content of the given comment

Source:

(inner) addElementToParagraphMargin(par, el)

Adds an element to the paragraph margin.

Parameters:
Name Type Description
par

Paragraph where the element will be added

el

Element to add

Source:

(inner) changeAnnotationPoints(id, points)

Changes annotation points.

Parameters:
Name Type Description
id

Annotation ID

points

Annotation points

Source:

(inner) changeVisibility(id, visibility)

Changes the visibility of an annotation. Visibility can be one of the following:

  • 1 = Myself
  • 2 = Document owner
  • 3 = Teacher
  • 4 = Everyone.
Parameters:
Name Type Description
id

Annoation ID

visibility

Annotation visibility (1, 2, 3 or 4)

Source:

(inner) checkIfAnnotation(element) → {boolean}

Checks if the given element is an annotation or not.

Parameters:
Name Type Description
element

Element to check

Source:
Returns:

Whether the element is an annotation or not

Type
boolean

(inner) createPopOverElement(annotation, show) → {Element}

Creates the actual (pop over) annotation element.

Parameters:
Name Type Description
annotation

Annotation info

show

Whether to show the annotation on creation or not

Source:
Returns:

Annotation element

Type
Element

(inner) createVelpBadge()

Creates the velp badge button (the button with letter 'V' on it).

Source:

(inner) deleteAnnotation(id, inmargin)

Deletes the given annotation.

Parameters:
Name Type Description
id

Annotation ID

inmargin

Whether annotation is a margin annotation or not

Source:

(inner) getAnnotationComments(id) → {Array}

Gets the comments of the given annotation.

Parameters:
Name Type Description
id

Marking ID

Source:
Returns:

Annotation comments

Type
Array

(inner) getAnnotationHighlight(points) → {string}

Get marking highlight style.

Parameters:
Name Type Description
points

Points given in marking

Source:
Returns:

Highlight style

Type
string

(inner) getAnnotationsByAnswerId(id) → {Array}

Gets all the annotations with a given answer ID.

Parameters:
Name Type Description
id

Answer ID

Source:
Returns:

Annotations of the answer

Type
Array

(inner) getAnswerInfo(start) → {Element|null}

Gets the answer info of the element. Returns null if no answer found.

Parameters:
Name Type Description
start

Paragraph where the answerbrowser element is searched for.

Source:
Returns:

answerbrowser element or null.

Type
Element | null

(inner) getElementChildren(element) → {Array}

Gets the children (not childNodes) of the element.

Parameters:
Name Type Description
element

Element whose children are requested

Source:
Returns:

Element children

Type
Array

(inner) getElementParent(element) → {Element}

Gets the parent element of the given element.

Parameters:
Name Type Description
element

Element whose parent is queried for

Source:
Returns:

Element parent

Type
Element

(inner) getElementParentUntilAttribute(element, attribute) → {Element}

Gets element parent element until given attribute is present.

Parameters:
Name Type Description
element

Element whose parent is queried for

attribute

Attribute as a string

Source:
Returns:

First element that has the given attribute

Type
Element

(inner) getElementPositionInTree(start, array) → {Array}

Gets an array of element indexes from the TIM paragraph element to the given element. TIM paragraph element is defined as an element containing a 't' attribute. If the given element is inside the TIM paragraph element, this method returns the following array: [0]. If the given element is inside the second child element of the TIM paragraph element, the following array is returned: [0, 1].

Parameters:
Name Type Description
start

Starting element

array

Array of indexes

Source:
Returns:

Array of element indexes

Type
Array

(inner) getNodeNumbers(el, aid, innerElement) → {Array}

Gets the start and end node numbers of created annotation element. Ignores annoations elements, but not elements inside it.

Parameters:
Name Type Description
el

Start container

aid

Annotation ID

innerElement

Annotation content

Source:
Returns:

Array with the start and end node numbers

Type
Array

(inner) getRealAnnotationId(id) → {int}

Returns the real ID of an annotation.

Parameters:
Name Type Description
id

Annotation ID generated by the client

Source:
Returns:

Annotation ID generated by the server

Type
int

(inner) getRealStartOffset(el, startoffset) → {int}

Get start offset according to the "original state" of DOM. Ignores annotation elements, but not the elements inside the annotation.

Parameters:
Name Type Description
el

Start container

startoffset

Original start offset

Source:
Returns:

Start offset according to the "original state" of the DOM.

Type
int

(inner) getVelpById(id) → {Object|null}

Gets the velp by its ID. If no velps are found, this method returns null.

Parameters:
Name Type Description
id

Velp to be found

Source:
Returns:

Velp or null

Type
Object | null

(inner) hasAnyIllegalClass(element) → {boolean}

Checks if the element has any class in illegalClasses array.

Parameters:
Name Type Description
element

Element to be checked

Source:
Returns:

Whether illegal classes were found or not.

Type
boolean

(inner) hasElementChildrenAnnotation(element) → {boolean}

Checks if the element children has an annotation element.

Parameters:
Name Type Description
element

Element to check

Source:
Returns:

Whether annotation was found or not

Type
boolean

(inner) hasSelectionChildrenAnnotation(range) → {boolean}

Checks recursively if the selection has any annotation elements as children.

Parameters:
Name Type Description
range

Range object containing the user's selection

Source:
Returns:

Whether the selection has any annotation elements as children or not

Type
boolean

(inner) hasSelectionParentAnnotation(range) → {boolean}

Checks iteratively if the element has an annotation element as its parent.

Parameters:
Name Type Description
range

Range object containing the user's selection

Source:
Returns:

Whether the element has an annotation element as its parent or not

Type
boolean

(inner) isSelectionTagParentsUnequal(range) → {boolean}

Checks if the selection breaks HTML tags. Returns true if the tags were broken.

Parameters:
Name Type Description
range

Range object containing the user's selection

Source:
Returns:

Whether the HTML tags were broken or not.

Type
boolean

(inner) loadAnnotationsToAnswer(answer_id, par_id)

Loads the annotations to the given answer.

Parameters:
Name Type Description
answer_id

Answer ID

par_id

Paragraph ID

Source:

(inner) loadDocumentAnnotations()

Loads the document annotations into the view.

Source:

(inner) makePostRequest(url, params, successMethod)

Makes a post request to the given URL.

Parameters:
Name Type Description
url

Request URL

params

Query parameters

successMethod

Method to run if the request was successful.

Source:

(inner) scrollToElement(element)

Scroll window to the given element.

Parameters:
Name Type Description
element

Element to scroll to.

Source:

(inner) selectText()

Selects text range or just the element.

Source:
To Do:
  • When annotations can break tags, check annotations from all elements in the selection.

(inner) toggleAnnotation(annotation)

Shows the annotation (despite the name).

Parameters:
Name Type Description
annotation

Annotation to be showed.

Source:
To Do:
  • If the annotation should be toggled, change all `showAnnotation()` methods to `toggleAnnotation()`.

(inner) updateAnnotation(id, inmargin)

Updates annotation data.

Parameters:
Name Type Description
id

Annotation ID

inmargin

Whether the annotation is to be placed in the margin or not

Source:

(inner) updateVelpBadge(oldElement, newElement)

Moves the velp badge to the correct element.

Parameters:
Name Type Description
oldElement

Element where the badge was

newElement

Element where the badge needs to be attached

Source:

(inner) useVelp(velp)

Adds an annotation with the selected velp's data to the selected text area or element.

Parameters:
Name Type Description
velp

Velp selected in the velpSelection directive

Source:
To Do:
  • When the annotations can cross HTML tags, end coordinate needs to be changed according to the end element.
  • Also get the paragraph element (parelement) according to endContainer.