Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 5b8f53f

Browse files
committed
Update after code review
Change some vue syntax Move regex into method with explanatory name Update translations Refactor method names
1 parent 8718865 commit 5b8f53f

File tree

6 files changed

+57
-51
lines changed

6 files changed

+57
-51
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"dependencies": {
2424
"@coderdojo/cd-common": "1.1.11",
2525
"bootstrap": "^3.4.1",
26-
"cp-translations": "1.0.135",
26+
"cp-translations": "1.0.137",
2727
"font-awesome": "^4.7.0",
2828
"handlebars": "^4.1.0",
2929
"js-cookie": "^2.1.4",

src/events/cd-event-form.vue

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="cd-event-form">
77
<h3 v-show="!editing" class="cd-event-form__header">{{ `${$t('Create an event for')} ${dojo.name}` }}</h3>
88
<h3 v-show="editing" class="cd-event-form__header">{{ `${$t('Edit event:')} ${eventName}` }}</h3>
9-
<form @submit="save">
9+
<form v-on:submit.prevent="save">
1010

1111
<div v-if="submitError">
1212
<h3 class="text-danger">{{ $t('There was an error processing this request. Please try again or contact support') }}</h3>
@@ -16,31 +16,32 @@
1616
<input type="text" data-cy="title" name="name" v-model="eventName" class="form-control" data-vv-name="eventName" v-validate="'required'" data-vv-validate-on="blur" :placeholder="$t('e.g. October Dojo')">
1717

1818
<div class="cd-event-form__location">
19-
{{ $t('This event uses the address') }}:
20-
<span v-show="!addressIsVisible">{{ formattedAddress }}</span>
21-
<i class="fa fa-pencil" @click="addressIsVisible = true" v-show="!addressIsVisible"></i>
22-
<i class="fa fa-times" @click="addressIsVisible = false" v-show="addressIsVisible"></i>
23-
<div v-if="addressIsVisible">
19+
{{ $t('Event address:') }}
20+
<span v-show="!customAddressFormIsVisible">{{ truncatedAddress }}</span>
21+
<i class="fa fa-pencil pointer" @click="customAddressFormIsVisible = true" v-show="!customAddressFormIsVisible"></i>
22+
<i class="fa fa-times pointer" @click="customAddressFormIsVisible = false" v-show="customAddressFormIsVisible"></i>
23+
<div v-if="customAddressFormIsVisible">
2424
<input type="text" name="city" v-model="eventCity" class="form-control">
2525
<textarea name="address" v-model="eventAddress" rows="3" class="form-control"></textarea>
2626
</div>
2727
</div>
2828

2929
<div class="cd-event-form__description">
30-
{{ $t('This event uses the description') }}:
31-
<span v-show="!descriptionIsVisible">{{ truncatedDescription }}</span>
32-
<i class="fa fa-pencil" @click="descriptionIsVisible = true" v-show="!descriptionIsVisible"></i>
33-
<i class="fa fa-times" @click="descriptionIsVisible = false" v-show="descriptionIsVisible"></i>
30+
{{ $t('Event description:') }}
31+
<span v-show="!customDescriptionFormIsVisible">{{ truncatedDescription }}</span>
32+
<i class="fa fa-pencil pointer" @click="customDescriptionFormIsVisible = true" v-show="!customDescriptionFormIsVisible"></i>
33+
<i class="fa fa-times pointer" @click="customDescriptionFormIsVisible = false" v-show="customDescriptionFormIsVisible"></i>
3434

3535
<p class="text-danger" v-show="errors.has('eventDescription:required')">{{ $t('Description is required') }}</p>
3636
<input type="hidden" v-model="eventDescription" v-validate="'required'" name="eventDescription" />
37-
<div v-if="descriptionIsVisible">
37+
<div v-if="customDescriptionFormIsVisible">
3838
<VueTrix v-model="eventDescription" ref="trixEditor" />
3939
</div>
4040
</div>
4141

4242
<h4 class="cd-event__section-title">{{ $t('Date and Time') }}</h4>
4343
<div>
44+
<p class="text-danger" v-show="errors.has('eventDate:required')">{{ $t('Event date is required') }}</p>
4445
<p class="text-danger" v-show="errors.has('startTime:required')">{{ $t('Start time is required') }}</p>
4546
<p class="text-danger" v-show="errors.has('endTime:required')">{{ $t('Finish time is required') }}</p>
4647
<p class="text-danger" v-show="errors.has('endTime:after')">{{ $t('Finish time must be after start time') }}</p>
@@ -51,27 +52,27 @@
5152
<VueCtkDateTimePicker v-model="eventDate"
5253
name="eventDate"
5354
v-validate="'required'"
54-
:only-date="true"
55-
:input-size="'sm'"
56-
:format="'YYYY-MM-DD'"
57-
:formatted="'ll'"
58-
:no-label=true
59-
:color="'#73449B'"
55+
only-date
56+
input-size="sm"
57+
format="YYYY-MM-DD"
58+
formatted="ll"
59+
no-label
60+
color="#73449B"
6061
/>
6162
</div>
6263

6364
<div class="col-sm-3 flow">
6465
<VueCtkDateTimePicker v-model="startTime"
6566
name="startTime"
66-
v-validate="'required'"
67-
:only-time="true"
68-
:input-size="'sm'"
69-
:format="'HH:mm'"
70-
:formatted="'HH:mm'"
71-
:minute-interval=10
72-
:no-label=true
67+
v-validate="'required|date_format:HH:mm'"
68+
only-time
69+
input-size="sm"
70+
format="HH:mm"
71+
formatted="HH:mm"
72+
minute-interval=10
73+
no-label
7374
ref="startTimePicker"
74-
:color="'#73449B'"
75+
color="#73449B"
7576
/>
7677
</div>
7778
<div class="col-sm-1 flow">
@@ -82,15 +83,15 @@
8283

8384
<div class="col-sm-3 flow">
8485
<VueCtkDateTimePicker v-model="endTime"
85-
v-validate="'date_format:HH:mm|after:startTimePicker'"
86+
v-validate="'required|date_format:HH:mm|after:startTimePicker'"
8687
name="endTime"
87-
:only-time="true"
88-
:input-size="'sm'"
89-
:format="'HH:mm'"
90-
:formatted="'HH:mm'"
91-
:minute-interval=10
92-
:no-label=true
93-
:color="'#73449B'"
88+
only-time
89+
input-size="sm"
90+
format="HH:mm"
91+
formatted="HH:mm"
92+
minute-interval=10
93+
no-label
94+
color="#73449B"
9495
/>
9596
</div>
9697
</div>
@@ -126,7 +127,7 @@
126127
</div>
127128
</form>
128129
<div class="flow">
129-
<p>We simplified our events experience, read <a href="TODO">about it here</a>.
130+
<p>We simplified our events experience, read <a href="https://coderdojo.com/?p=17691">about it here</a>.
130131
<br/>
131132
If you need to customise your event further you can still use the <a :href="`/dashboard/dojo/${dojo.id}/event-form`">advanced events form</a></p>
132133
</div>
@@ -158,8 +159,8 @@
158159
},
159160
data() {
160161
return {
161-
addressIsVisible: false,
162-
descriptionIsVisible: false,
162+
customAddressFormIsVisible: false,
163+
customDescriptionFormIsVisible: false,
163164
dojo: {},
164165
editing: false,
165166
latestEvent: undefined,
@@ -186,6 +187,10 @@
186187
EventStore.commit('setDojoId', this.dojo.id);
187188
EventStore.commit('setCreatedBy', this.loggedInUser.id);
188189
},
190+
stripHtml(htmlString) {
191+
// removes html tags and non breaking spaces
192+
return htmlString.replace(/(<[^<|>]+?>)|(&nbsp;)/gi, ' ');
193+
},
189194
async validateForm() {
190195
try {
191196
const res = await this.$validator.validateAll();
@@ -195,8 +200,7 @@
195200
}
196201
},
197202
198-
async save(e) {
199-
e.preventDefault();
203+
async save() {
200204
const valid = await this.validateForm();
201205
if (valid) {
202206
try {
@@ -279,12 +283,12 @@
279283
},
280284
},
281285
truncatedDescription() {
282-
const str = EventStore.getters.description.replace(/(<[^<|>]+?>)|(&nbsp;)/gi, ' ');
286+
const str = this.stripHtml(EventStore.getters.description);
283287
const words = str.split(' ').filter(word => word !== '');
284288
return `${words.slice(0, 6).join(' ')}... `;
285289
},
286-
formattedAddress() {
287-
const str = EventStore.getters.address.replace(/(<[^<|>]+?>)|(&nbsp;)/gi, ' ');
290+
truncatedAddress() {
291+
const str = this.stripHtml(EventStore.getters.address);
288292
const words = str.split(' ').filter(word => word !== '');
289293
return `${words.slice(0, 5).join(' ')}... ${this.eventCity}`;
290294
},
@@ -358,4 +362,8 @@
358362
width: 100%;
359363
}
360364
}
365+
366+
.pointer {
367+
cursor: pointer;
368+
}
361369
</style>

src/events/event-store.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// import Vue from 'vue';
21
import Vuex from 'vuex';
32
import moment from 'moment';
43

test/unit/specs/events/cd-event-form.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,22 @@ describe('Event Form component', () => {
200200
});
201201
});
202202
});
203-
describe('formattedAddress', () => {
203+
describe('truncatedAddress', () => {
204204
it('formats the address correctly', () => {
205205
const vm = vueUnitHelper(EventFormWithMocks);
206206
MockEventStore.getters = {
207207
address: '<p>123 Fake Street</p>',
208208
city: 'London',
209209
};
210-
expect(vm.formattedAddress).to.eql('123 Fake Street... London');
210+
expect(vm.truncatedAddress).to.eql('123 Fake Street... London');
211211
});
212212
it('truncates address to 5 words', () => {
213213
const vm = vueUnitHelper(EventFormWithMocks);
214214
MockEventStore.getters = {
215215
address: '<p>123 Really Really Long Named Fake Street</p>',
216216
city: 'London',
217217
};
218-
expect(vm.formattedAddress).to.eql('123 Really Really Long Named... London');
218+
expect(vm.truncatedAddress).to.eql('123 Really Really Long Named... London');
219219
});
220220
});
221221
});

test/unit/specs/events/event-store.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import moment from 'moment';
22
import EventStore from '@/events/event-store';
3-
// import { mutations } from '@/events/event-store';
43

54
describe('Event Store', () => {
65
let clock;

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,10 +2044,10 @@ cosmiconfig@^2.1.0, cosmiconfig@^2.1.1:
20442044
parse-json "^2.2.0"
20452045
require-from-string "^1.1.0"
20462046

2047-
2048-
version "1.0.135"
2049-
resolved "https://registry.yarnpkg.com/cp-translations/-/cp-translations-1.0.135.tgz#2de3c053ca52214017b9c1a26718b36d68bb7e38"
2050-
integrity sha512-zlJhrzBN/28ABPjb7LVjlzojsCp7fgaNq3/9zfTddsYAmlakcSrIR0m6B3rmHbkcDb79ox/dGrBSvYD8i91BhA==
2047+
2048+
version "1.0.137"
2049+
resolved "https://registry.yarnpkg.com/cp-translations/-/cp-translations-1.0.137.tgz#c36d6448e1fa50687f9d9f3c911a6aa3dbca67ca"
2050+
integrity sha512-ixLhpXSltTEwBSDsfbXS/r1V3K4LM9nCgoDsSDFmcN6asejbINVeOzgXMQVcDUg7w9ynUau3bxtwYIKvgmo0Qg==
20512051

20522052
crc32-stream@^2.0.0:
20532053
version "2.0.0"

0 commit comments

Comments
 (0)