File : core/ViewerFileLoader.js

1
/*
2
Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/
3
4
This  program is free software;
5
you can redistribute it and/or modify it under the terms of the
6
GNU General Public License as published by the Free Software Foundation;
7
either version 3 of the License, or any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
*/
18
/*
19
Changes:
20
    - v4.0.0:
21
        - created from v3.6.0
22
Doc reviewed 202208
23
 */
24
25
import theTravelNotesData from '../data/TravelNotesData.js';
26
import theEventDispatcher from './lib/EventDispatcher.js';
27
import FileCompactor from './lib/FileCompactor.js';
28
import Zoomer from './Zoomer.js';
29
import { ROUTE_EDITION_STATUS, INVALID_OBJ_ID } from '../main/Constants.js';
30
31
/* ------------------------------------------------------------------------------------------------------------------------- */
32
/**
33
This class load a file from a web server and display the travel
34
*/
35
/* ------------------------------------------------------------------------------------------------------------------------- */
36
37
class ViewerFileLoader {
38
39
    /**
40
    The constructor
41
    */
42
43
    constructor ( ) {
44
        Object.freeze ( this );
45
    }
46
47
    /**
48
    Open a distant file from a web server and display the content of the file
49
    @param {JsonObject} travelJsonObject the json object readed from the file
50
    */
51
52
    openDistantFile ( travelJsonObject ) {
53
        new FileCompactor ( ).decompress ( travelJsonObject );
54
        theTravelNotesData.travel.jsonObject = travelJsonObject;
55
        theTravelNotesData.travel.readOnly = true;
56
        document.title =
57
            'Travel & Notes' +
58
            ( '' === theTravelNotesData.travel.name ? '' : ' - ' + theTravelNotesData.travel.name );
59
        const routesIterator = theTravelNotesData.travel.routes.iterator;
60
        while ( ! routesIterator.done ) {
61
            if ( ROUTE_EDITION_STATUS.notEdited === routesIterator.value.editionStatus ) {
62
                theEventDispatcher.dispatch (
63
                    'routeupdated',
64
                    {
65
                        removedRouteObjId : INVALID_OBJ_ID,
66
                        addedRouteObjId : routesIterator.value.objId
67
                    }
68
                );
69
            }
70
            else {
71
                theTravelNotesData.editedRouteObjId = routesIterator.value.objId;
72
            }
73
        }
74
75
        if ( INVALID_OBJ_ID !== theTravelNotesData.editedRouteObjId ) {
76
            theEventDispatcher.dispatch (
77
                'routeupdated',
78
                {
79
                    removedRouteObjId : INVALID_OBJ_ID,
80
                    addedRouteObjId : theTravelNotesData.travel.editedRoute.objId
81
                }
82
            );
83
        }
84
        const notesIterator = theTravelNotesData.travel.notes.iterator;
85
        while ( ! notesIterator.done ) {
86
            theEventDispatcher.dispatch (
87
                'noteupdated',
88
                {
89
                    removedNoteObjId : INVALID_OBJ_ID,
90
                    addedNoteObjId : notesIterator.value.objId
91
                }
92
            );
93
        }
94
        new Zoomer ( ).zoomToTravel ( );
95
    }
96
97
}
98
99
export default ViewerFileLoader;
100
101
/* --- End of file --------------------------------------------------------------------------------------------------------- */
102