| Conditions | 1 |
| Paths | 1 |
| Total Lines | 148 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 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); |
||
| 44 | }, |
||
| 45 | n: function(app, textSingular, textPlural, count, vars, options) { |
||
| 46 | return OC.L10N.translatePlural(app, textSingular, textPlural, count, vars, options); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | }); |
||
| 50 | |||
| 51 | let newPoll = new Vue({ |
||
| 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'); |
||
| 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) |
||
| 157 | .then((response) => { |
||
| 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); |
||
| 162 | }, (error) => { |
||
| 163 | console.log(error.response); |
||
| 164 | }); |
||
| 165 | } |
||
| 166 | }, |
||
| 167 | |||
| 168 | loadPoll: function (hash) { |
||
| 169 | axios.get(OC.generateUrl('apps/polls/get/poll/' + hash)) |
||
| 170 | .then((response) => { |
||
| 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) => { |
||
| 181 | console.log(error.response); |
||
| 182 | }); |
||
| 183 | } |
||
| 184 | }, |
||
| 185 | }); |
||
| 186 | } |
||
| 187 | } |
||
| 188 |
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: