Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RES-1953 When a group has no events, on the Fixometer page, make it clearer how they can add data #700

Merged
merged 5 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/Device.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,13 @@ public static function getItemTypes()
// ANY_VALUE is used to suppress errors when SQL mode is not set to ONLY_FULL_GROUP_BY.
$types = DB::select(DB::raw("
SELECT item_type,
ANY_VALUE(powered) AS powered,
ANY_VALUE(idcategories) AS idcategories,
ANY_VALUE(categoryname)
MAX(powered) AS powered,
MAX(idcategories) AS idcategories,
MAX(categoryname)
FROM (SELECT DISTINCT s.*
FROM (SELECT item_type,
ANY_VALUE(powered) AS powered,
ANY_VALUE(idcategories) AS idcategories,
MAX(powered) AS powered,
MAX(idcategories) AS idcategories,
categories.name AS categoryname,
COUNT(*) AS count
FROM devices
Expand All @@ -450,8 +450,8 @@ public static function getItemTypes()
JOIN (SELECT item_type,
MAX(count) AS maxcount
FROM (SELECT item_type AS item_type,
ANY_VALUE(powered) AS powered,
ANY_VALUE(idcategories) AS idcategories,
MAX(powered) AS powered,
MAX(idcategories) AS idcategories,
categories.name AS categoryname,
COUNT(*) AS count
FROM devices
Expand Down
21 changes: 0 additions & 21 deletions app/Http/Controllers/API/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,6 @@ public static function getGroupList()
return response()->json($groups);
}

public static function getEventsForGroup(Request $request, Group $group)
{
// Used by old JS client.
$group = $group->load('parties');

$events = $group->parties->sortByDesc('event_start_utc');

if ($request->has('format') && $request->input('format') == 'location') {
$events = $events->map(function ($event) {
return (object) [
'id' => $event->idevents,
'location' => $event->FriendlyLocation,
];
});
}

return response()->json([
'events' => $events->values()->toJson(),
]);
}

/**
* @OA\Get(
* path="/api/v2/groups/names",
Expand Down
4 changes: 3 additions & 1 deletion lang/en/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,7 @@
'made_host' => 'We have made :name a host for this group.',
'permission' => 'Sorry, you do not have permission to do this.',
'volunteer_remove_success' => 'We have removed :name from this group.',
'volunteer_remove_error' => 'We are unable to remove :name from this group.'
'volunteer_remove_error' => 'We are unable to remove :name from this group.',
'create_event_first' => 'Please first create an event in order to add repair data.',
'follow_group_first' => 'Repair data is added to community repair events. Please first follow a group and then choose an event in order to add repair data.',
];
2 changes: 2 additions & 0 deletions lang/fr-BE/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,6 @@
'permission' => 'Désolé, vous n\'avez pas la permission de faire ça.',
'volunteer_remove_success' => 'Nous avons retiré :name de ce Repair Café.',
'volunteer_remove_error' => 'Nous ne sommes pas en mesure de supprimer :name de ce Repair Café.',
'create_event_first' => 'Veuillez d\'abord créer un événement afin d\'ajouter des données de réparation.',
'follow_group_first' => 'Les données de réparation sont ajoutées aux événements de réparation de la communauté. Veuillez d\'abord suivre un Repair Café, puis choisir un événement afin d\'ajouter des données de réparation.',
];
2 changes: 2 additions & 0 deletions lang/fr/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,6 @@
'permission' => 'Désolé, vous n\'avez pas la permission de faire ça.',
'volunteer_remove_success' => 'Nous avons retiré :name de ce Repair Café.',
'volunteer_remove_error' => 'Nous ne sommes pas en mesure de supprimer :name de ce Repair Café.',
'create_event_first' => 'Veuillez d\'abord créer un événement afin d\'ajouter des données de réparation.',
'follow_group_first' => 'Les données de réparation sont ajoutées aux événements de réparation de la communauté. Veuillez d\'abord suivre un Repair Café, puis choisir un événement afin d\'ajouter des données de réparation.',
];
1 change: 0 additions & 1 deletion resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ require('slick-carousel');
require('ekko-lightbox');
require('bootstrap4-datetimepicker');
require('./misc/notifications');
require('./fixometer');
require('leaflet');
require('./constants');

Expand Down
133 changes: 133 additions & 0 deletions resources/js/components/AddDataModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<template>
<b-modal
id="addData"
v-model="showModal"
no-stacking
no-body
size="md"
title-class="w-100 p-0"
header-class="p-0"
body-class="p-0"
title-tag="h2"
>
<template slot="modal-title">
{{ __('devices.add_data_title') }}
<hr class="hr-dashed mb-25 mt-10">
</template>
<div>
{{ __('devices.add_data_description') }}
</div>
<b-alert v-if="!groups.length && !fetching" show variant="warning" class="mt-2">
{{ __('groups.follow_group_first') }}
</b-alert>
<div v-else>
<label for="items_cat" class="mt-2">{{ __('devices.add_data_group') }}:</label>
<b-select v-model="groupId" :options="groupOptions" id="group_member" />
<b-alert v-if="groupId && !events.length && !fetching" variant="warning" class="mt-2" show>
{{ __('groups.create_event_first') }}
</b-alert>
<div v-else>
<label for="items_cat" class="mt-2">{{ __('devices.add_data_event') }}:</label>
<b-select :disabled="fetching" v-model="eventId" :options="eventOptions" id="events" />
</div>
</div>
<template slot="modal-footer">
<b-button v-if="!groups.length && !fetching" href="/group" variant="primary">
{{ __('dashboard.see_all_groups') }}
</b-button>
<b-button v-else-if="groupId && !events.length && !fetching" variant="primary" size="sm" @click="createEvent" :disabled="!groupId">
{{ __('events.create_event') }}
</b-button>
<b-button v-else variant="primary" size="sm" @click="gotoEvent">
{{ __('devices.add_data_action_button') }}
</b-button>
</template>
</b-modal>
</template>
<script>
import moment from 'moment'
export default {
data: function() {
return {
showModal: false,
groupId: null,
eventId: null,
fetching: false,
}
},
computed: {
groups() {
let groups = this.$store.getters['groups/list']
return groups ? groups.sort((a, b) => {
return a.name.localeCompare(b.name)
}) : []
},
events() {
const events = Object.values(this.$store.getters['events/getAll'])
return events.sort((a,b) => new moment(b.start).unix() - new moment(a.start).unix())
},
groupOptions() {
return this.groups.map(g => {
return {
value: g.idgroups,
text: g.name
}
})
},
eventOptions() {
return this.events.map(e => {
return {
value: e.id,
text: new moment(e.start).format('DD MMM YY') + ' / ' + e.title
}
})
},
},
watch: {
groupId: {
immediate: true,
handler: async function (newVal) {
if (newVal) {
this.fetching = true
await this.$store.dispatch('events/clear')
await this.$store.dispatch('events/fetchByGroup', {
id: newVal
})
await this.$nextTick()
if (this.events.length) {
this.eventId = this.events[0].id
}
this.fetching = false
}
}
}
},
methods: {
show() {
this.showModal = true
if (this.groups.length) {
this.groupId = this.groups[0].idgroups
}
},
hide() {
this.showModal = false
},
gotoEvent() {
if (this.eventId) {
window.location = '/party/view/' + this.eventId + '#devices-section'
}
},
createEvent() {
window.location = '/party/create/' + this.groupId
},
}
}
</script>
7 changes: 7 additions & 0 deletions resources/js/components/EventAddEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ export default {
required: false,
default: false
},
createGroup: {
type: Number,
required: false,
default: null
}
},
data () {
return {
Expand Down Expand Up @@ -270,6 +275,8 @@ export default {
// and so that as/when it changes then reactivity updates all the views.
//
// Further down the line this may change so that the data is obtained via an AJAX call and perhaps SSR.
this.idgroups = this.createGroup
this.$store.dispatch('groups/setList', {
groups: this.groups
})
Expand Down
6 changes: 6 additions & 0 deletions resources/js/components/EventAddEditPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<b-card no-body class="box mt-4">
<b-card-body class="p-4">
<EventAddEdit :duplicate-from="currentdup" :idevents="currentid" :groups="groups" :csrf="csrf"
:create-group="createGroup"
@created="eventCreated" @edited="justCreated = false" :just-created="justCreated"
:can-approve="canApprove" :can-network="canNetwork"
:key="bump" />
Expand Down Expand Up @@ -47,6 +48,11 @@ export default {
required: false,
default: false
},
createGroup: {
type: Number,
required: false,
default: null
}
},
data() {
return {
Expand Down
18 changes: 15 additions & 3 deletions resources/js/components/FixometerHeading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<b-img src="/images/fixometer_doodle.svg" class="ml-4 d-none d-md-block" />
</div>
<div>
<b-btn variant="primary" data-target="#add-device-modal" data-toggle="modal">
<b-btn variant="primary" @click="addData">
{{ __('devices.add_data_button') }}
</b-btn>
</div>
Expand All @@ -19,8 +19,21 @@
<b>{{ __('devices.huge_impact') }}</b>
<span v-html="__('devices.impact_read_more')" />
</p>
<AddDataModal ref="addData" />
</div>
</template>
<script>
import AddDataModal from "./AddDataModal";
export default {
components: { AddDataModal },
methods: {
addData() {
this.$refs.addData.show()
}
}
}
</script>
<style scoped lang="scss">
@import 'resources/global/css/_variables';
@import '~bootstrap/scss/functions';
Expand All @@ -30,5 +43,4 @@
.border-top-very-thick {
border-top: 5px solid $black;
}
</style>
</style>
9 changes: 8 additions & 1 deletion resources/js/components/FixometerPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ export default {
isAdmin: {
type: Boolean,
required: true
},
userGroups: {
type: Array,
required: true,
}
},
data () {
Expand Down Expand Up @@ -265,7 +269,6 @@ export default {
if (params.has('model')) {
this.model = params.get('model')
console.log("Got modal ", this.model)
this.startExpandedItems = true
}
Expand Down Expand Up @@ -301,6 +304,10 @@ export default {
this.total_powered = this.impactData.total_powered
this.total_unpowered = this.impactData.total_unpowered
this.$store.dispatch('groups/setList', {
groups: this.userGroups
})
},
watch: {
url(newVal) {
Expand Down
44 changes: 0 additions & 44 deletions resources/js/fixometer.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So long, fixometer.js!

This file was deleted.

Loading