Completed
Branch vue-create-webpack (d93d8a)
by René
06:31
created

app.js ➔ ... ➔ ???   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
c 2
b 0
f 0
nc 3
nop 1
dl 0
loc 11
rs 9.4285
1
/**
2
 * @copyright 2017 Christoph Wurst <[email protected]>
3
 *
4
 * @author 2017 Christoph Wurst <[email protected]>
5
 *
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
import Vue from 'vue';
0 ignored issues
show
Configuration introduced by
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
24
import axios from 'axios';
0 ignored issues
show
Configuration introduced by
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
25
import moment from 'moment';
0 ignored issues
show
Configuration introduced by
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
26
import lodash from 'lodash';
0 ignored issues
show
Configuration introduced by
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
27
28
import AuthorDiv from './components/authorDiv.vue';
0 ignored issues
show
Configuration introduced by
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
29
import Breadcrump from './components/breadcrump.vue';
0 ignored issues
show
Configuration introduced by
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
30
import DatePickerInline from './components/datePickerInline.vue';
0 ignored issues
show
Configuration introduced by
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
31
import DatePickerInput from './components/datePickerInput.vue';
0 ignored issues
show
Configuration introduced by
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
32
import DatePollItem from './components/datePollItem.vue';
0 ignored issues
show
Configuration introduced by
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
33
import SideBarClose from './components/sideBarClose.vue';
0 ignored issues
show
Configuration introduced by
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
34
import TextPollItem from './components/textPollItem.vue';
0 ignored issues
show
Configuration introduced by
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
35
import TimePicker from './components/timePicker.vue';
0 ignored issues
show
Configuration introduced by
'import' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
36
		Vue.config.devtools = true;
37
38
export class App {
0 ignored issues
show
Configuration introduced by
'export' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
Backwards Compatibility introduced by
'class' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
39
	start() {
40
		Vue.mixin({
41
			methods: {
42
				t: function(app, text, vars, count, options) {
43
					return OC.L10N.translate(app, text, vars, count, options);
0 ignored issues
show
Bug introduced by
The variable OC seems to be never declared. If this is a global, consider adding a /** global: OC */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
44
				},
45
				n: function(app, textSingular, textPlural, count, vars, options) {
46
					return OC.L10N.translatePlural(app, textSingular, textPlural, count, vars, options);
0 ignored issues
show
Bug introduced by
The variable OC seems to be never declared. If this is a global, consider adding a /** global: OC */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
47
				}
48
			}
49
		});
50
51
		let newPoll = new Vue({
0 ignored issues
show
Unused Code introduced by
The variable newPoll seems to be never used. Consider removing it.
Loading history...
Backwards Compatibility introduced by
'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
52
			el: '#app',
53
			data: {
54
				poll: {
55
					mode: 'create',
56
					event: {
57
						id: 0,
58
						hash: '',
59
						type: 'datePoll',
60
						title: '',
61
						description: '',
62
						owner:'',
63
						created: '',
64
						access: 'public',
65
						expiration: false,
66
						expire: null,
67
						isAnonymous: false,
68
						fullAnonymous: false,
69
						disallowMaybe: false,
70
					},
71
					options: {
72
						pollDates: [],
73
						pollTexts:[]
74
					}
75
				},
76
				lang: 'de', //lang: OC.getLocale(),
77
				localeData: moment.localeData(moment.locale('de')), // localeData: moment.localeData(moment.locale(OC.getLocale())),
78
				placeholder: '',
79
				newPollDate: '',
80
				newPollTime: '',
81
				newPollText: '',
82
				nextPollDateId: 0,
83
				nextPollTextId: 0,
84
				protect: false,
85
				sidebar: false,
86
				titleEmpty: false
87
			},
88
89
			components: {
90
				'author-div': AuthorDiv,
91
				'breadcrump': Breadcrump,
92
				'date-picker-inline': DatePickerInline,
93
				'date-picker-input': DatePickerInput,
94
				'date-poll-item': DatePollItem,
95
				'side-bar-close': SideBarClose,
96
				'text-poll-item': TextPollItem,
97
				'time-picker': TimePicker
98
			},
99
			
100
			mounted: function() {
101
				this.poll.event.hash = document.getElementById("app").getAttribute("data-hash"); 
102
				if (this.poll.event.hash !== '') {
103
					this.loadPoll(this.poll.event.hash);
104
					this.protect = true;
105
					this.poll.mode = 'edit';
106
				}
107
			},
108
			
109
			computed: {
110
				title: function () {
111
					if (this.poll.event.title === '') {
112
						return t('poll','Create new poll');
113
					} else {
114
						return this.poll.event.title;
115
					}
116
				}
117
			},
118
			
119
			methods: {
120
				switchSidebar: function() {
121
					this.sidebar = !this.sidebar;
122
				},
123
124
				addNewPollDate: function (newPollDate, newPollTime) {
125
					if (newPollTime !== undefined) {
126
						this.newPollDate = moment(newPollDate +' ' + newPollTime);
127
					} else {
128
						this.newPollDate = moment(newPollDate);
129
					}
130
					this.poll.options.pollDates.push({
131
						id: this.nextPollDateId++,
132
						timestamp: moment(newPollDate).unix(),
133
					});
134
					this.poll.options.pollDates = _.sortBy(this.poll.options.pollDates, 'timestamp');
0 ignored issues
show
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
135
				},
136
				
137
				addNewPollText: function (newPollText) {
138
					if (newPollText !== null) {
139
						this.newPollText = newPollText;
140
					}
141
					this.poll.options.pollTexts.push({
142
						id: this.nextPollTextId++,
143
						text: this.newPollText
144
					});
145
					this.newPollText = '';
146
				},
147
148
				writePoll: function (mode) {
149
					if (mode !== '') {
150
						this.poll.mode = mode;
151
					}
152
					if (this.poll.event.title.length === 0) {
153
						this.titleEmpty = true;
154
					} else {
155
						this.titleEmpty = false;
156
						axios.post(OC.generateUrl('apps/polls/write'), this.poll)
0 ignored issues
show
Bug introduced by
The variable OC seems to be never declared. If this is a global, consider adding a /** global: OC */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
157
							.then((response) => {
0 ignored issues
show
Configuration introduced by
'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
158
								this.poll.mode = 'edit';
159
								this.poll.event.hash = response.data.hash;
160
								this.poll.event.id = response.data.id;
161
								window.location.href = OC.generateUrl('apps/polls/edit/' + this.poll.event.hash);
0 ignored issues
show
Bug introduced by
The variable OC seems to be never declared. If this is a global, consider adding a /** global: OC */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
162
							}, (error) => {
0 ignored issues
show
Configuration introduced by
'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
163
								console.log(error.response);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
164
						});
165
					}
166
				},
167
				
168
				loadPoll: function (hash) {
169
					axios.get(OC.generateUrl('apps/polls/get/poll/' + hash))
0 ignored issues
show
Bug introduced by
The variable OC seems to be never declared. If this is a global, consider adding a /** global: OC */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
170
					.then((response) => {
0 ignored issues
show
Configuration introduced by
'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
171
						var i;
172
						this.poll = response.data.poll;
173
						if (response.data.poll.event.type === 'datePoll') {
174
							for (i = 0; i < response.data.poll.options.pollTexts.length; i++) {
175
								this.addNewPollDate(new Date(moment.utc(response.data.poll.options.pollTexts[i].text)));
176
								// this.addNewPollDate(new Date(response.data.poll.options.pollTexts[i].text)  +' UTC');
177
							}
178
						this.poll.options.pollTexts = [];
179
						}
180
					}, (error) => {
0 ignored issues
show
Configuration introduced by
'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

Generally using ECMAScript 6 specific syntax is fine if you are sure that it is already supported by all engines which are supposed to run this code.

Further Reading:

Loading history...
181
						console.log(error.response);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
182
					});
183
				}
184
			},
185
		});
186
	}
187
}
188