libreoffice-online/loleaflet
Pranav Kant 68b3a2c81e Always save irrespective of nature of socket close
Do not distinguish between normal shutdown or abnormal shutdown.
Also remove 'disconnect' frame to indicate normal shutdown.

Change-Id: I98fd9f5a219feb1097c57302dba14e08ad9bf143
2016-04-13 17:35:10 +05:30
..
build loleaflet: bccu#1622, add a marker progress bar 2016-03-31 21:33:48 -04:00
debug loleaflet: ws:// -> wss:// 2016-03-23 22:02:50 +01:00
dist loleaflet: We do not use underscores in identifier names 2016-04-13 11:47:22 +05:30
docs loleaflet: load jquery in the reference.html 2015-11-12 19:22:30 +02:00
node_modules
plugins/draw-0.2.4 tdf#94600: Do not reposition corner markers on 'dragend' 2016-01-27 10:10:15 +00:00
po loleaflet: remove 'product' reference 2016-04-01 12:50:17 +02:00
spec loleaflet: ws:// -> wss:// 2016-03-23 22:02:50 +01:00
src Always save irrespective of nature of socket close 2016-04-13 17:35:10 +05:30
util New loleaflet toolbar 2016-02-08 18:32:01 +01:00
.eslintignore loleaflet: Support for memory subscription 2016-03-13 19:40:52 +05:30
.eslintrc
.gitignore Hush - update gitignores. 2016-04-07 19:38:33 +01:00
.npmignore
.travis.yml
CHANGELOG.md
FAQ.md
Jakefile.js
LICENSE
loleaflet.spec.in
Makefile bump version number, because we branched off 1.5.x 2016-04-10 12:53:06 +02:00
package.json loleaflet: headless load test 2015-08-19 11:48:49 +03:00
PLUGIN-GUIDE.md
README Update READMEs for SSL and Admin panel 2016-03-22 16:09:22 +05:30
reference.html loleaflet: Trigger locontextmenu event with the context menu structure. 2016-04-08 19:15:08 +02:00

Leaflet platform for LibreOffice On-Line
========================================

This is the client part of LibreOffice On-Line.  For the server part, see the
../loolwsd/README, and install it first.

Build dependencies
------------------

First you need to install 'jake'.  As root, do:

    npm install -g jake
    npm install

npm is provided by the nodejs package.
Alternatively, you can use the provided zip (as a normal user):

    unzip node_modules/modules.zip -d node_modules

A third way is to use npm as a user, but set its prefix to a directory where
you have write access. If you want that, you need to have an ~/.npmrc with the
line e.g.

    prefix=/opt/npm

Building
--------

As a normal user:

    jake build
    cd plugins/draw-0.2.4
    jake build

Running
-------

To see an example:

* run loolwsd, like:

    ./loolwsd --systemplate=${SYSTEMPLATE} --lotemplate=${MASTER}/instdir --childroot=${ROOTFORJAILS}

Note that this will, by default, set the loolwsd's file server's root to the parent directory of loolwsd,
which means you can access all the files in loleaflet using /loleaflet/ path. It is advised to set
fileserverroot manually for more control. See loolwsd/README for more information.

* open debug/document/document_simple_example.html or dist/loleaflet.html through loolwsd's fileserver

    https://localhost:9980/loleaflet/dist/loleaflet.html?file_path=file:///PATH/TO_DOC&host=wss://localhost:9980

and you should see the document in the browser.  In case anything goes wrong,
check the loolwsd console for the debugging output. You might be asked to confirm the certificate if you
are using self-signed certificate for loolwsd.

Admin Panel
-----------

You can do live monitoring of all the user sessions running on loolwsd instance. To access the admin
console you need to ask for admin.html file from loolwsd which resides in dist/admin/admin.html.

For example:

    https://localhost:9980/loleaflet/dist/admin/admin.html

It will ask for username and password which, by default, are 'admin', 'admin' respectively. After entering
the correct password you should be able to monitor the live documents opened, total users, memory consumption,
document URLs with number of users viewing that document etc. You can also kill the documents directly from
the panel which would result in closing the socket connection to the respective document.

Testing
-------
    - to run the unit tests
        + open spec/loleaflet.html in the browser
    - to simulate an editing session and to get the tile loading times
        + open spec/tilebench.html in the browser
    - to simulate a client opening several documents in the browser
        + open spec/loadtest.html in the browser
    - to simulate a client opening several documents in the console
        + run: node_modules/.bin/mocha spec/headlessLoadTest.js
    - to simulate multiple clients opening several documents in the console
        + run: make load-test

The structure of the unit tests:
Loleaflet unit tets are located under spec/loleaflet. Following Leaflet's testing style, each test's path
should mirror the source's path, so spec/loleaflet/control/ToolbarSpec.js tests the features from
src/control/Toolbar.js . Any new test file needs also to be added in spec/leaflet.html


API & events
------------

######################################################################
# See /loleaflet/reference.html for a better formated documentation. #
# See /loolwsd/reference.txt for the HTTP API documentation.         #
######################################################################

Search:
    - API:
        map.search(text, [backward])
        map.higlightAll(text)
    - events:
        map.on('search', function (e) {}) (currently only fired when no search result is found) where:
            + e.originalPhrase = the phrase that has been searched for
            + e.count = number of results
            + e.results = [SearchResult], where SearchResult = {part: part, rectangles: [Bounds]}

Zoom:
    - API:
        map.zoomIn(amount)
        map.zoomOut(amount)
        map.getMinZoom()
        map.getMaxZoom()
    - events:
        map.on('zoomend zoomlevelschange', function)

Edit, view, readOnly:
    - API:
        map.setPermission('edit' | 'view' | 'readonly')
    - events:
        map.on('updatepermission', function (e) {}) where:
            + e.perm == 'edit' | 'view' | 'readonly'

Buttons like Bold, Italic, Strike through etc.
    - API:
        map.toggleCommandState('.uno:' + 'Bold' | 'Italic' | 'Underline' | 'Strikeout' |
            'LeftPara' | 'CenterPara' | 'RightPara' | 'JustifyPara' |
            'IncrementIndent' | 'DecrementIndent'
    - events:
        map.on('commandstatechanged', function (e) {}) where:
            + e.commandName == '.uno:' + 'Bold' | 'Italic' | 'StyleApply' | 'CharFontName' | 'FontHeight' etc.
            + e.state = 'true' | 'false'
            + e.state = fontName | fontSize | styleName
        map.on('commandresult', function (e) {}) where:
            + e.commandName == '.uno:' + 'Bold' | 'Italic' | 'StyleApply' | 'CharFontName' | 'FontHeight' etc.
            + e.success = true | false | undefined

Parts (like slides in presentation, or sheets in spreadsheets):
    - API:
        map.setPart('next' | 'prev' | partNumber)
        map.getNumberOfParts()
        map.getCurrentPartNumber()
        map.getPreview(id, index, maxWidth, maxHeight, [options])
            + id = the ID of the request so that the response can be identified
            + index = the part / page 's number
            + maxWidth / maxHeight = max dimensions so that the ratio is preserved
            + options = {autoUpdate: true} - automatically updates the previews
        map.getCustomPreview(id, part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, [options])
            + id = the ID of the request so that the response can be identified
            + part = the part containing the desired preview
            + width / height = the preview's size in pixels
            + tilePosX / tilePosY = the rectangles's starting position in twips
            + tileWidth / tileHeight = the rectangle's dimension in twips
            + options = {autoUpdate: true} - automatically updates the previews
        map.removePreviewUpdate(id)
            + id = the preview's id

    - events:
        map.on('updateparts', function (e) {}) where:
            + e.selectedPart is the current part
            + e.parts == the number of parts that the document has
            + e.docType == 'text' | 'spreadsheet' | 'presentation' | 'drawing' | 'other'
            + [e.partNames] if present, part names (e.g. sheet names)
        map.on('invalidatepreview', function (e) {})
            + e.id = the preview's id
        map.on('tilepreview', function (e) {}) where:
            + e.tile - the preview image
            + e.id - the preview id
            + e.width - width of the image
            + e.height - height of the image
            + [e.part] - if the preview is for a part
            + e.docType

Statusindicator (when the document is loading):
    - events
        map.on('statusindicator', function (e) {}) where:
            + e.statusType = 'start' | 'setvalue' | 'finish' | 'loleafletloaded' | 'alltilesloaded'
            + e.value == a value from 0 to 100 indicating the status
              if the statusType is 'setvalue
            + 'loleafletloaded' is fired when the JS code is initialized and the document
                load request is sent and we're waiting for the tiles
            + 'alltilesloaded' is fired when all newly requested (empty tiles) have been loaded
                it is not fired during pre-fetching and during editing

Save:
    - API:
        map.saveAs(url, [format, options])
        map.downloadAs(name, [format, options])

Scroll (the following are measured in pixels):
    - API:
            + options = An object with members: update (type: Boolean, default: false)
                like {update: true}
        map.scroll(x,y, options)
            + scroll right by 'x' and down by 'y' (or left and up if negative)
        map.scrollDown(y, options)
            + scroll down by 'y' (or up if negative)
        map.scrollRight(x, options)
            + scroll right by 'x' (or left if negative)
        map.scrollTop(y, options)
            + scroll to 'y' offset relative to the beginning of the document
        map.scrollLeft(x, options)
            + scroll to 'x' offset relative to the beginning of the document
        map.scrollOffset()
            + returns the scroll offset relative to the beginning of the document
        map.getDocSize()
            + returns the document's size in pixels
        map.getDocType()
            + returns 'text' | 'spreadsheet' | 'presentation' | 'drawing' | 'other'
    - events
        map.on('docsize', function (e) {}) where:
            + e.x = document width
            + e.y = document height
        map.on('updatescrolloffset', function (e) {}) where:
            + e.x = difference between document's left and current view's left
                (how much has the document been scrolled right)
            + e.y = difference between document's top and current view's top
                (how much has the document been scrolled down)
            - this event is fired when zooming and the current view is maintained but the
                document shrinks or grow OR when the document is panned OR when the container is resized
        map.on('scrollto', function (e) {}) where:
            + e.x = view's left position (so that the cursor/search result is in the center)
            + e.y = view's top position (so that the cursor/search result is in the center)
        map.on('scrollby', function (e) {}) where:
            + e.x = the amount scrolled to the right (or left if negative)
            + e.y = the amount scrolled to the bottom (or top if negative)

Writer pages:
    - API:
        map.goToPage(page)
        map.getNumberOfPages()
        map.getCurrentPageNumber()
        map.getPreview(id, index, maxWidth, maxHeight, [options])
            + id = the ID of the request so that the response can be identified
            + index = the part / page 's number
            + maxWidth / maxHeight = max dimensions so that the ratio is preserved
            + options = {autoUpdate: true} - automatically updates the previews
        map.getCustomPreview(id, part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, [options])
            + id = the ID of the request so that the response can be identified
            + part = the part containing the desired preview
            + width / height = the preview's size in pixels
            + tilePosX / tilePosY = the rectangles's starting position in twips
            + tileWidth / tileHeight = the rectangle's dimension in twips
            + options = {autoUpdate: true} - automatically updates the previews
        map.removePreviewUpdate(id)
            + id = the preview's id
        map.getPageSizes()
            + returns {twips: [Bounds], pixels: [Bounds]}

    - events
        map.on('pagenumberchanged', function (e) {}) where:
            + e.currentPage = the page on which the cursor lies
            + e.pages = number of pages
            + e.docType = document type, should be 'text'
        map.on('invalidatepreview', function (e) {})
            + e.id = the preview's id
        map.on('partpagerectangles', function (e) {}) where:
            + e.pixelRectangles = An array of bounds representing each page's dimension in pixels on the current zoom level
            + e.twipsRectangles = An array of bounds representing each page's dimension in twips.

Error:
    - events
        map.on('error', function (e) {}) where
            + [e.msg] = a message describing the error
            + [e.cmd] = the command that caused the error
            + [e.kind] = the kind of error

CommandValues:
    - api:
        map.getToolbarCommandValues(command)
            + returns a JSON mapping of all possible values for the command
        map.applyFont(fontName)
        map.applyFontSize(fontSize)
        map.applyStyle(style, styleFamily)
    - events
        map.on('updatetoolbarcommandvalues', function (e) {}) where
            + e.commandName = '.uno:StyleApply', etc
            + e.commandValues = a JSON mapping of all possible values for the command

Print:
    - events
        map.on('print', function (e) {}) where
            + e.url = file download url

Contributing
------------

Code conventions:

    * 'jake lint' should be run before commiting
    * files should have unix line terminators (LF)
    * tools to convert files: dos2unix or fromdos

Implementation details
----------------------

Loading a document:
    The map should have the following options:
        - server address
        - doc - path to the document that will be loaded
        - edit = the initial permission
        - readOnly - whether the document is read only
        - [timestamp] - optionally provided for remote documents

How zooming works:
    The zoom level goes from 1 to 20 (those limits can be changed) and the initial
    level is 10, which represents the 100% zoom level. The zoom factor is 1.2

Controls are added above the map in a div called "controls" is intended to be used as a toolbar.
There is no leaflet method of adding them in a separate div, so for now this is done in the html
document after the map initialization.

To enable scrollbars the map is placed above a div that contains a bigger div of
the document's size (a mock document). So the div under the map gets scrollbars which
are independent of the map's div, thus enabling us to link them to the map as needed.
When the user scrolls, the map is panned by the same amount as it would've been scrolled.
Also, some custom jquery scrollbars are used, to trigger the same scroll events across
browsers.