Failed Conditions
Pull Request — master (#59)
by Sander
01:24
created

js/app/app.js (5 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
/**
2
 * Nextcloud - NextNotes
3
 *
4
 * @copyright Copyright (c) 2016, Sander Brand ([email protected])
5
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected])
6
 * @license GNU AGPL version 3 or any later version
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License as
10
 * published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
23
(function () {
24
	'use strict';
25
26
	/**
27
	 * @ngdoc overview
28
	 * @name passmanApp
29
	 * @description
30
	 * # passmanApp
31
	 *
32
	 * Main module of the application.
33
	 */
34
	angular
35
		.module('NextNotesApp', [
36
			'ngAnimate',
37
			'ngCookies',
38
			'ngResource',
39
			'ngRoute',
40
			'ngSanitize',
41
			'ngTouch',
42
			'templates-main',
43
			'ui.tinymce',
44
			'yaru22.angular-timeago',
45
			'xeditable'
46
		])
47
		.config(['$httpProvider', function ($httpProvider) {
48
			/** global: oc_requesttoken */
49
			$httpProvider.defaults.headers.common.requesttoken = oc_requesttoken;
50
		}]).config(['$qProvider', function ($qProvider) {
51
		$qProvider.errorOnUnhandledRejections(false);
52
	}]).run(['$rootScope', 'NoteFactory', 'editableOptions', function ($rootScope, NoteFactory, editableOptions) {
53
		editableOptions.theme = 'bs2';
54
		console.log('App loaded');
55
		$rootScope.list_sorting = {
56
			what: 'name',
57
			reverse: true
58
		};
59
		$rootScope.noteGroupFilter = {
60
			grouping: 'all'
61
		};
62
		$rootScope.list_filter = {
63
			deleted: 0
64
		};
65
		$rootScope.OC = OC;
66
		$rootScope.sidebar_shown = true;
67
68
		$rootScope.$on('show_sidebar', function (evt, state) {
69
			$rootScope.sidebar_shown = state;
70
		});
71
72
		function loadNotes () {
73
			NoteFactory.query(function (notes) {
74
				console.log('Notes received', notes);
75
				$rootScope.notes = notes;
76
				$rootScope.$broadcast('nextnotes_notes_loaded');
77
				$rootScope.keys = Object.keys;
78
79
				// Fix nextcloud's behaviour because templates are injected with JS.
80
				$rootScope.$on('$viewContentLoaded', function () {
81
					$(window).trigger('resize');
82
				});
83
				$(window).trigger('resize');
84
85
86
				//Setup locale data
87
				$rootScope.dateFormat = moment.localeData().longDateFormat('L').replace(/D/g, 'd').replace(/Y/g, 'y');
88
				$rootScope.dateFormatLong = moment.localeData().longDateFormat('L').replace(/D/g, 'd').replace(/Y/g, 'y') + ' H:mm';
89
			});
90
		}
91
92
		loadNotes();
93
		$rootScope.$on('refresh_notes', function () {
94
			loadNotes();
95
		});
96
97
98
		// Setup a watcher on the notes so groups are always correct
99
		// @TODO Implement multi level support
100
101
102
		var getGroupIndexByName = function (groupName) {
103
			for (var i = 0; i < $rootScope.note_groups.length; i++) {
104
				if (groupName === $rootScope.note_groups[i].name) {
105
					return i;
106
				}
107
			}
108
			return -1;
109
		};
110
111
		$rootScope.$watch('[notes, list_filter]', function (n) {
112
			if (!n) {
113
				return;
114
			}
115
116
			$rootScope.note_groups = [];
117
			$rootScope.note_count = 0;
118
119
			var notes = $rootScope.notes;
120
			angular.forEach(notes, function (note) {
121
				if (note.hasOwnProperty('id')) {
122
					if (note.deleted !== $rootScope.list_filter.deleted) {
123
						return;
124
					}
125
					$rootScope.note_count++;
126
					if(shareMode === 'standalone'){
127
						var name = (OC.getCurrentUser().uid === note.owner.uid ) ? note.grouping : note.grouping + ' ('+ note.owner.uid +')';
128
					} else {
129
						var name = note.grouping;
0 ignored issues
show
It seems like name was already defined.
Loading history...
130
					}
131
					var idx = getGroupIndexByName(name);
0 ignored issues
show
The variable name seems to be used out of scope.

This error can usually be fixed by declaring the variable in the scope where it is used:

function someFunction() {
    (function() {
        var i = 0;
    })();

    // i is not defined.
    alert(i);
}

// This can be fixed by moving the var statement to the outer scope.

function someFunction() {
    var i;
    (function() {
        i = 1;
    })();

    alert(i);
};
Loading history...
132
					if (shareMode === 'merge' && idx === -1 && note.grouping !== '_new' && note.grouping !== '') {
133
						$rootScope.note_groups.push({
134
							name: name,
0 ignored issues
show
The variable name seems to be used out of scope.

This error can usually be fixed by declaring the variable in the scope where it is used:

function someFunction() {
    (function() {
        var i = 0;
    })();

    // i is not defined.
    alert(i);
}

// This can be fixed by moving the var statement to the outer scope.

function someFunction() {
    var i;
    (function() {
        i = 1;
    })();

    alert(i);
};
Loading history...
135
							note_count: 1
136
						});
137
					}
138
					if (shareMode === 'standalone' && idx === -1 && note.grouping !== '_new' && note.grouping !== '') {
139
							$rootScope.note_groups.push({
140
							name: name,
0 ignored issues
show
The variable name seems to be used out of scope.

This error can usually be fixed by declaring the variable in the scope where it is used:

function someFunction() {
    (function() {
        var i = 0;
    })();

    // i is not defined.
    alert(i);
}

// This can be fixed by moving the var statement to the outer scope.

function someFunction() {
    var i;
    (function() {
        i = 1;
    })();

    alert(i);
};
Loading history...
141
							note_count: 1
142
						});
143
					}
144
					if (shareMode === 'standalone' && idx !== -1 && note.grouping !== '_new' && note.grouping !== '') {
145
						var name = (OC.getCurrentUser().uid === note.owner.uid ) ? note.grouping : note.grouping + ' ('+ note.owner.uid +')';
0 ignored issues
show
It seems like name was already defined.
Loading history...
146
						$rootScope.note_groups[idx].note_count++;
147
					}
148
					if (shareMode === 'merge' && idx !== -1 && note.grouping !== '_new' && note.grouping !== '') {
149
						$rootScope.note_groups[idx].note_count++;
150
					}
151
				}
152
			});
153
		}, true);
154
	}]);
155
}());
156