Skip to content

Commit 26a2ecf

Browse files
authored
Merge pull request #229 from IFRCGo/bugfix/WN-274
WN-274,
2 parents 1a8b05f + c046cbf commit 26a2ecf

File tree

7 files changed

+62
-17
lines changed

7 files changed

+62
-17
lines changed

resources/assets/js/methods/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,13 @@ export const methods = {
126126
},
127127
markdown: value => markdown.toHTML(value),
128128
getLangName: value => languages[value] ? languages[value].native : value,
129-
hazardIcon (str, store) {
129+
hazardIcon (str, hazardsList = []) {
130130
if (str === 'Create Hazard Type' || str === 'create') {
131131
return require('../../img/icons/[email protected]')
132132
}
133133

134134
let hazardUrl = null
135-
if (store) {
136-
const hazardsList = store.getters['content/hazardsList']
135+
if (hazardsList.length) {
137136
const hazard = hazardsList.find(h => h.name === str || h.icon === str)
138137
if (hazard) {
139138
hazardUrl = hazard.url

resources/assets/js/pages/content/editWhatnow.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<hr>
3333
<div :class="`c-file-upload ${newHazardValidations.validated && (newHazardValidations.icon === false) ? 'is-invalid' : ''}`">
3434
<label for="newHazardIcon" class="upload-label">
35-
<b-img :src="hazardIcon('create', this.$store)" class="upload-icon" width="60" height="60" alt="" role="presentation"></b-img>
35+
<b-img :src="hazardIcon('create', hazardsList)" class="upload-icon" width="60" height="60" alt="" role="presentation"></b-img>
3636
<span class="upload-text">{{$t('hazard_type.create.upload_icon')}}</span>
3737
</label>
3838

resources/assets/js/pages/content/whatnow.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ export default {
509509
this.attributionPublishing = false
510510
this.addingNewLanguage = false
511511
this.editing = false
512+
this.languageToAdd = null
512513
} catch (e) {
513514
// Find index of translation we've just edited so we can find it in the response from the server
514515
this.updateErrors.indexError = this.attributionToEdit.translations.findIndex(translation => translation.languageCode === this.selectedLanguage)

resources/assets/js/pages/content/whatnowContentItem.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<b-card-header header-tag="header" class="pl-2 pt-3 pb-3 pr-2 rounded-bottom" role="tab">
4141
<div class="d-flex justify-content-start align-items-center">
4242
<div>
43-
<b-img :src="hazardIcon(content.eventType, this.$store)" class="rounded-circle" width="60" height="60"></b-img>
43+
<b-img :src="hazardIcon(content.eventType, hazardsList)" class="rounded-circle" width="60" height="60"></b-img>
4444
</div>
4545
<div class="ml-2 rtl-mr-2">
4646
<h4 class="subtitle">{{ content.currentTranslation.title }}</h4>
@@ -116,7 +116,7 @@ import swal from 'sweetalert2'
116116
import WhatnowMessageCard from './whatnowMessageCard'
117117
118118
export default {
119-
props: ['selectedLanguage', 'content', 'isPromo', 'regionSlug', 'forceCreate', 'selectedSoc', 'disabled'],
119+
props: ['selectedLanguage', 'content', 'isPromo', 'regionSlug', 'forceCreate', 'selectedSoc', 'disabled', 'hazardsList'],
120120
components: {
121121
WhatnowMessageCard,
122122
},

resources/assets/js/pages/content/whatnowList.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
:regionSlug="selectedRegion?.title"
4848
:selectedSoc="selectedSoc"
4949
:disabled="disabled"
50+
:hazardsList="hazardsList"
5051
>
5152
</whatnow-content-item>
5253
<whatnow-content-item
@@ -61,6 +62,7 @@
6162
:forceCreate="true"
6263
:selectedSoc="selectedSoc"
6364
:disabled="disabled"
65+
:hazardsList="hazardsList"
6466
>
6567
</whatnow-content-item>
6668
</transition-group>
@@ -112,6 +114,7 @@ export default {
112114
},
113115
mounted () {
114116
this.fetch()
117+
this.fetchAllHazardTypes()
115118
},
116119
watch: {
117120
selectedLanguage: {
@@ -171,12 +174,20 @@ export default {
171174
}
172175
}
173176
}
174-
}
177+
},
178+
async fetchAllHazardTypes() {
179+
try {
180+
await this.$store.dispatch('content/fetchHazardTypes')
181+
} catch (e) {
182+
this.$noty.error(this.$t('error_alert_text'))
183+
}
184+
},
175185
},
176186
computed: {
177187
...mapGetters({
178188
user: 'auth/user',
179-
currentContent: 'content/currentContent'
189+
currentContent: 'content/currentContent',
190+
hazardsList: 'content/hazardsList',
180191
}),
181192
hazardSelected (val) {
182193
return this.selectedHazard

resources/assets/js/pages/content/whatnowPreviewer.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div class="card-content">
1818
<div class="title-section">
1919
<div class="previsualizer-key-message-icon small-icon icon-spacing">
20-
<b-img :src="hazardIcon(eventType, this.$store)" class="rounded-circle" width="40" height="40"></b-img>
20+
<b-img :src="hazardIcon(eventType, hazardsList)" class="rounded-circle" width="40" height="40"></b-img>
2121
</div>
2222
<h4>{{title}}</h4>
2323
</div>
@@ -43,6 +43,7 @@
4343
</template>
4444

4545
<script>
46+
import { mapGetters } from 'vuex'
4647
import html2canvas from 'html2canvas'
4748
import Loading from '../../components/Loading'
4849
import jsPDF from 'jspdf'
@@ -56,6 +57,9 @@ export default {
5657
loading: false,
5758
}
5859
},
60+
mounted() {
61+
this.fetchAllHazardTypes()
62+
},
5963
methods: {
6064
async downloadAsPNG() {
6165
this.loading = true;
@@ -157,8 +161,19 @@ export default {
157161
} finally {
158162
this.loading = false;
159163
}
160-
}
161-
164+
},
165+
async fetchAllHazardTypes() {
166+
try {
167+
await this.$store.dispatch('content/fetchHazardTypes')
168+
} catch (e) {
169+
this.$noty.error(this.$t('error_alert_text'))
170+
}
171+
},
172+
},
173+
computed: {
174+
...mapGetters({
175+
hazardsList: 'content/hazardsList',
176+
})
162177
}
163178
}
164179
</script>

resources/assets/js/pages/view_data/whatnow.vue

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
<b-row v-if="hazardsList" class="ml-4 mr-4 pl-4 pr-4 pb-3 pt-3 selects-container d-flex align-items-center justify-content-start" v-show="selectedSoc">
1919
<b-col cols="auto" class="d-flex align-items-center">
20-
<selectSociety :selected.sync="selectedSoc" :staynull="true" :dontfilter="true" @optionUpdated="watchOptionUpdated"></selectSociety>
20+
<SimpleSelectSociety class="mr-3" v-model="selectedSoc" :societyList="filteredSocieties" :countryCode="countryCode">
21+
</SimpleSelectSociety>
2122
<p class="ml-2 mb-0">{{ selectedSoc ? selectedSoc.label : 'Select a society' }}</p>
2223
</b-col>
2324
<b-col cols="auto" v-if="hazardsList" class="d-flex align-items-center">
@@ -55,12 +56,14 @@
5556

5657
<script>
5758
import SelectSociety from '~/pages/content/selectSociety'
59+
import SimpleSelectSociety from '~/pages/content/simpleSocietyPicker'
5860
import WhatnowList from '~/pages/content/whatnowList'
5961
import { mapGetters } from 'vuex'
6062
import Spooky from '~/components/global/Spooky'
6163
import axios from 'axios'
6264
import PageBanner from '~/components/PageBanner'
6365
import { languages } from 'countries-list'
66+
import * as permissionsList from '../../store/permissions'
6467
6568
export default {
6669
props: {
@@ -73,7 +76,8 @@ export default {
7376
SelectSociety,
7477
Spooky,
7578
WhatnowList,
76-
PageBanner
79+
PageBanner,
80+
SimpleSelectSociety,
7781
},
7882
data () {
7983
return {
@@ -82,7 +86,8 @@ export default {
8286
loadingContent: false,
8387
currentTranslations: null,
8488
selectedHazard: null,
85-
languages
89+
languages,
90+
currentLanguages: ['en'],
8691
}
8792
},
8893
watch: {
@@ -144,14 +149,20 @@ export default {
144149
}
145150
return flattened
146151
})
152+
this.currentLanguages = this.selectedSoc.translations.map((transl) => transl.languageCode)
147153
}
154+
148155
},
149156
watchOptionUpdated (val) {
150-
console.log('watchOptionUpdated', val)
151157
if (!val) {
152158
this.$router.push({ path: '/data/whatnow' });
153159
}
154160
},
161+
async getData() {
162+
this.$store.dispatch('content/fetchOrganisations').then(() => {
163+
this.selectedSoc = this.filteredSocieties.find((soc) => soc.countryCode === this.countryCode)
164+
})
165+
},
155166
},
156167
metaInfo () {
157168
return { title: this.$t('content.whatnow.whatnow') }
@@ -173,11 +184,19 @@ export default {
173184
locale: 'lang/locale',
174185
user: 'auth/user',
175186
currentContent: 'content/currentContent',
176-
currentLanguages: 'content/currentLanguages',
177-
societies: 'content/organisations'
187+
societies: 'content/organisations',
178188
}),
179189
hazardsList () {
180190
return this.currentTranslations
191+
},
192+
filteredSocieties() {
193+
if (this.user) {
194+
if (this.can(this.user, permissionsList.ALL_ORGANISATIONS)) {
195+
return this.societies
196+
}
197+
return this.societies.filter(soc => this.user.data.organisations.indexOf(soc.countryCode) !== -1)
198+
}
199+
return this.societies
181200
}
182201
}
183202
}

0 commit comments

Comments
 (0)