diff --git a/app/Device.php b/app/Device.php index 1cf48faec4..6767989937 100644 --- a/app/Device.php +++ b/app/Device.php @@ -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 @@ -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 diff --git a/app/Http/Controllers/API/GroupController.php b/app/Http/Controllers/API/GroupController.php index 86a3f665d2..896d5ca0bc 100644 --- a/app/Http/Controllers/API/GroupController.php +++ b/app/Http/Controllers/API/GroupController.php @@ -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", diff --git a/lang/en/groups.php b/lang/en/groups.php index e68717f6b0..74f0ad9309 100644 --- a/lang/en/groups.php +++ b/lang/en/groups.php @@ -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.', ]; diff --git a/lang/fr-BE/groups.php b/lang/fr-BE/groups.php index cc6f64b8cd..7b2a483080 100644 --- a/lang/fr-BE/groups.php +++ b/lang/fr-BE/groups.php @@ -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.', ]; diff --git a/lang/fr/groups.php b/lang/fr/groups.php index 48031b50b3..cd535b7aff 100644 --- a/lang/fr/groups.php +++ b/lang/fr/groups.php @@ -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.', ]; diff --git a/resources/js/app.js b/resources/js/app.js index 50b3701067..860b26125c 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -12,7 +12,6 @@ require('slick-carousel'); require('ekko-lightbox'); require('bootstrap4-datetimepicker'); require('./misc/notifications'); -require('./fixometer'); require('leaflet'); require('./constants'); diff --git a/resources/js/components/AddDataModal.vue b/resources/js/components/AddDataModal.vue new file mode 100644 index 0000000000..9693a8e9f9 --- /dev/null +++ b/resources/js/components/AddDataModal.vue @@ -0,0 +1,133 @@ + + \ No newline at end of file diff --git a/resources/js/components/EventAddEdit.vue b/resources/js/components/EventAddEdit.vue index a3a42dd63a..ca074074e5 100644 --- a/resources/js/components/EventAddEdit.vue +++ b/resources/js/components/EventAddEdit.vue @@ -180,6 +180,11 @@ export default { required: false, default: false }, + createGroup: { + type: Number, + required: false, + default: null + } }, data () { return { @@ -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 }) diff --git a/resources/js/components/EventAddEditPage.vue b/resources/js/components/EventAddEditPage.vue index 176763b27a..1b5b47487d 100644 --- a/resources/js/components/EventAddEditPage.vue +++ b/resources/js/components/EventAddEditPage.vue @@ -7,6 +7,7 @@ @@ -47,6 +48,11 @@ export default { required: false, default: false }, + createGroup: { + type: Number, + required: false, + default: null + } }, data() { return { diff --git a/resources/js/components/FixometerHeading.vue b/resources/js/components/FixometerHeading.vue index 860495394e..35f9ff0263 100644 --- a/resources/js/components/FixometerHeading.vue +++ b/resources/js/components/FixometerHeading.vue @@ -6,7 +6,7 @@
- + {{ __('devices.add_data_button') }}
@@ -19,8 +19,21 @@ {{ __('devices.huge_impact') }}

+ + \ No newline at end of file + diff --git a/resources/js/components/FixometerPage.vue b/resources/js/components/FixometerPage.vue index f5e00c4d6a..4f090d295e 100644 --- a/resources/js/components/FixometerPage.vue +++ b/resources/js/components/FixometerPage.vue @@ -211,6 +211,10 @@ export default { isAdmin: { type: Boolean, required: true + }, + userGroups: { + type: Array, + required: true, } }, data () { @@ -265,7 +269,6 @@ export default { if (params.has('model')) { this.model = params.get('model') - console.log("Got modal ", this.model) this.startExpandedItems = true } @@ -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) { diff --git a/resources/js/fixometer.js b/resources/js/fixometer.js deleted file mode 100644 index e557658953..0000000000 --- a/resources/js/fixometer.js +++ /dev/null @@ -1,44 +0,0 @@ -function searchEventsByGroup() { - $group_id = $(".change-group :selected").val(); - - if ($group_id == null) { - return false; - } - - $.ajax({ - headers: { - 'X-CSRF-TOKEN': $("input[name='_token']").val() - }, - type: 'GET', - url: '/api/groups/'+ $group_id + '/events?format=location', - datatype: 'json', - success: function(response) { - $('.change-events option').remove(); - $events = JSON.parse(response.events) - - $.each($events, function($key, $event) { - var data = { - id: $event.id, - text: $event.location - }; - - var newOption = new Option(data.text, data.id, false, false); - $('.change-events').append(newOption).trigger('change'); - }); - - console.log('Success: Found ' + $('.change-events option').length + ' events.'); - }, - }); -} - -$(document).ready(function() { - searchEventsByGroup(); - - $('.change-group').on('change', function() { - searchEventsByGroup(); - }); - - $('.change-events').on('change', function() { - $('.change-event-url').attr('href', '/party/view/' + $(this).val() + '#devices-section'); - }); -}); diff --git a/resources/js/store/events.js b/resources/js/store/events.js index 4a5190ee49..4c2a3c3c69 100644 --- a/resources/js/store/events.js +++ b/resources/js/store/events.js @@ -68,6 +68,9 @@ export default { } }, mutations: { + clear(state) { + state.list = {} + }, set(state, params) { // There is a separate store for devices. Make sure we don't accidentally use the list of devices returned // on the object, because that isn't updated dynamically. @@ -76,7 +79,7 @@ export default { }, setList(state, params) { params.events.forEach(e => { - Vue.set(state.list, e.idevents, e) + Vue.set(state.list, e.id, e) }) }, setModerate(state, params) { @@ -92,6 +95,9 @@ export default { }, }, actions: { + clear({commit}) { + commit('clear') + }, set({commit}, params) { commit('set', params); }, @@ -185,6 +191,19 @@ export default { } catch (e) { console.error("Events fetch failed", e) } + }, + async fetchByGroup({ rootGetters, commit }, params) { + try { + let ret = await axios.get('/api/v2/groups/' + params.id + '/events?api_token=' + rootGetters['auth/apiToken']) + + commit('setList', { + events: ret.data.data + }) + + return ret.data.data + } catch (e) { + console.error("Events fetch by group failed", e) + } } }, } \ No newline at end of file diff --git a/resources/views/events/create.blade.php b/resources/views/events/create.blade.php index 6a00775346..6a244f5d56 100644 --- a/resources/views/events/create.blade.php +++ b/resources/views/events/create.blade.php @@ -29,6 +29,7 @@ :groups="{{ json_encode($user_groups, JSON_INVALID_UTF8_IGNORE) }}" @endif :can-approve="{{ (App\Helpers\Fixometer::hasRole( Auth::user(), 'Administrator') || ($selected_group_id && Auth::user()->isCoordinatorForGroup(App\Group::find($selected_group_id)))) ? "true" : "false" }}" + :create-group="{{ $selected_group_id ? $selected_group_id : 'null' }}" /> diff --git a/resources/views/fixometer/add-data-modal.blade.php b/resources/views/fixometer/add-data-modal.blade.php deleted file mode 100644 index 8fe0f9a528..0000000000 --- a/resources/views/fixometer/add-data-modal.blade.php +++ /dev/null @@ -1,66 +0,0 @@ - - diff --git a/resources/views/fixometer/index.blade.php b/resources/views/fixometer/index.blade.php index b62ccedcad..1aaf6e0930 100644 --- a/resources/views/fixometer/index.blade.php +++ b/resources/views/fixometer/index.blade.php @@ -23,11 +23,10 @@ :barrier-list="{{ json_encode($barriers, JSON_INVALID_UTF8_IGNORE) }}" :item-types="{{ json_encode($item_types, JSON_INVALID_UTF8_IGNORE) }}" :is-admin="{{ App\Helpers\Fixometer::hasRole($user, 'Administrator') ? 'true' : 'false' }}" + :user-groups="{{ json_encode($user_groups, JSON_INVALID_UTF8_IGNORE) }}" /> -@endsection - -@include('fixometer.add-data-modal') \ No newline at end of file +@endsection \ No newline at end of file diff --git a/resources/views/svgs/fixometer/fixometer-doodle.blade.php b/resources/views/svgs/fixometer/fixometer-doodle.blade.php deleted file mode 100644 index 8be4383169..0000000000 --- a/resources/views/svgs/fixometer/fixometer-doodle.blade.php +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/routes/api.php b/routes/api.php index 7c7a6d7fe1..249a76f8fe 100644 --- a/routes/api.php +++ b/routes/api.php @@ -57,8 +57,6 @@ Route::delete('/usersgroups/{id}', [API\UserGroupsController::class, 'leave']); // Used by Vue client. }); -Route::get('/groups/{group}/events', [API\GroupController::class, 'getEventsForGroup']); // Used by old JS client. - Route::get('/devices/{page}/{size}', [App\Http\Controllers\ApiController::class, 'getDevices']); // Used by Vue client. // Notifications info. We don't authenticate this, as API keys don't exist for all users. There's no real privacy diff --git a/tests/Feature/Events/CreateEventTest.php b/tests/Feature/Events/CreateEventTest.php index 7f897d59f2..17ea1663af 100644 --- a/tests/Feature/Events/CreateEventTest.php +++ b/tests/Feature/Events/CreateEventTest.php @@ -123,20 +123,11 @@ public function a_host_with_a_group_can_create_an_event($data) assertSee($eventAttributes['venue']); // Check that the event appears in the API. - $rsp = $this->get('/api/groups/' . $group->idgroups . '/events'); - $rsp->assertStatus(200); - $json = json_decode($rsp->getContent(), true); - $events = json_decode($json['events']); - self::assertEquals(1, count($events)); - self::assertEquals($event->idevents, $events[0]->idevents); - - $rsp = $this->get('/api/groups/' . $group->idgroups . '/events?format=location'); - $rsp->assertStatus(200); - $json = json_decode($rsp->getContent(), true); - $events = json_decode($json['events']); - self::assertEquals(1, count($events)); - self::assertEquals($event->idevents, $events[0]->id); - self::assertEquals($event->FriendlyLocation, $events[0]->location); + $response = $this->get("/api/v2/groups/{$group->idgroups}/events"); + $response->assertSuccessful(); + $json = json_decode($response->getContent(), true); + $this->assertEquals(1, count($json['data'])); + $this->assertEquals($event->idevents, $json['data'][0]['id']); // Now check whether the event shows/doesn't show correctly for different user roles. list($role, $seeEvent, $canModerate) = $data;