From 88e85d2dfbba8e71b91c9dd165084ca64241414f Mon Sep 17 00:00:00 2001
From: Nick Peelman
Date: Mon, 18 Jul 2016 08:49:38 -0400
Subject: [PATCH 1/6] group components on manage subscriptions page
---
app/Http/Controllers/SubscribeController.php | 9 +++--
app/Presenters/ComponentGroupPresenter.php | 22 +++++++++++++
resources/assets/js/app.js | 22 +++++++++++++
.../views/partials/component_input.blade.php | 18 ++++++++++
.../views/partials/components_form.blade.php | 33 +++++++++++++++++++
resources/views/subscribe/manage.blade.php | 32 ++++--------------
6 files changed, 109 insertions(+), 27 deletions(-)
create mode 100644 resources/views/partials/component_input.blade.php
create mode 100644 resources/views/partials/components_form.blade.php
diff --git a/app/Http/Controllers/SubscribeController.php b/app/Http/Controllers/SubscribeController.php
index 104dfd8cfb3f..14911a9215dc 100644
--- a/app/Http/Controllers/SubscribeController.php
+++ b/app/Http/Controllers/SubscribeController.php
@@ -18,6 +18,7 @@
use CachetHQ\Cachet\Bus\Commands\Subscriber\UpdateSubscriberSubscriptionCommand;
use CachetHQ\Cachet\Bus\Commands\Subscriber\VerifySubscriberCommand;
use CachetHQ\Cachet\Models\Component;
+use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Cachet\Models\Subscription;
use GrahamCampbell\Binput\Facades\Binput;
@@ -147,15 +148,19 @@ public function showManage($code = null)
}
$subscriber = Subscriber::where('verify_code', '=', $code)->first();
+ $usedComponentGroups = Component::enabled()->where('group_id', '>', 0)->groupBy('group_id')->pluck('group_id');
+ $componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
+ $ungroupedComponents = Component::enabled()->where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
if (!$subscriber) {
throw new BadRequestHttpException();
}
return View::make('subscribe.manage')
- ->withComponents(Component::all())
+ ->withUngroupedComponents($ungroupedComponents)
->withSubscriber($subscriber)
- ->withSubscriptions($subscriber->subscriptions->pluck('component_id')->all());
+ ->withSubscriptions($subscriber->subscriptions->pluck('component_id')->all())
+ ->withComponentGroups($componentGroups);
}
/**
diff --git a/app/Presenters/ComponentGroupPresenter.php b/app/Presenters/ComponentGroupPresenter.php
index 9aebc48369f0..91967f5e0927 100644
--- a/app/Presenters/ComponentGroupPresenter.php
+++ b/app/Presenters/ComponentGroupPresenter.php
@@ -97,4 +97,26 @@ public function toArray()
'lowest_human_status' => $this->lowest_human_status(),
]);
}
+
+ /**
+ * Determine if any of the contained components have active subscriptions
+ *
+ * @return bool
+ */
+ public function has_subscriber($subscriptions)
+ {
+ $enabled_components = $this->wrappedObject->enabled_components()->orderBy('order')->pluck('id')->toArray();
+ $intersected = array_intersect($enabled_components, $subscriptions);
+ return count($intersected) != 0;
+ }
+
+ /**
+ * Determine the class for collapsed/uncollapsed groups on the subscription form.
+ *
+ * @return string
+ */
+ public function collapse_class_with_subscriptions($subscriptions)
+ {
+ return $this->has_subscriber($subscriptions) ? 'ion-ios-minus-outline' : 'ion-ios-plus-outline';
+ }
}
diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js
index bc890c5ae876..6511596edc02 100644
--- a/resources/assets/js/app.js
+++ b/resources/assets/js/app.js
@@ -277,6 +277,28 @@ $(function() {
$this.next('.group-items').toggleClass('hide');
});
+ $('.select-group').on('click', function () {
+ var $this = $(this);
+ var $parentGroup = $this.closest('ul.list-group');
+ $parentGroup.find('input[type=checkbox]').prop('checked', true);
+
+ $parentGroup.find('.group-items').removeClass('hide')
+ $parentGroup.find('.group-toggle').addClass('ion-ios-minus-outline').removeClass('ion-ios-plus-outline');
+ event.stopPropagation();
+ return false;
+ });
+
+ $('.deselect-group').on('click', function () {
+ var $this = $(this);
+ var $parentGroup = $this.closest('ul.list-group');
+ $parentGroup.find('input[type=checkbox]').prop('checked', false);
+
+ $parentGroup.find('.group-items').addClass('hide');
+ $parentGroup.find('.group-toggle').removeClass('ion-ios-minus-outline').addClass('ion-ios-plus-outline');
+ event.stopPropagation();
+ return false;
+ });
+
// Setup wizard
$('.wizard-next').on('click', function () {
var $form = $('#setup-form'),
diff --git a/resources/views/partials/component_input.blade.php b/resources/views/partials/component_input.blade.php
new file mode 100644
index 000000000000..abbc5f76536a
--- /dev/null
+++ b/resources/views/partials/component_input.blade.php
@@ -0,0 +1,18 @@
+
+
+
+
+ @if($component->description)
+
+ @endif
+
+
diff --git a/resources/views/partials/components_form.blade.php b/resources/views/partials/components_form.blade.php
new file mode 100644
index 000000000000..5e31c33d84bd
--- /dev/null
+++ b/resources/views/partials/components_form.blade.php
@@ -0,0 +1,33 @@
+@if($component_groups->count() > 0)
+@foreach($component_groups as $componentGroup)
+
+ @if($componentGroup->enabled_components->count() > 0)
+ -
+
+ {{ $componentGroup->name }}
+
+
+
+ @foreach($componentGroup->enabled_components()->orderBy('order')->get() as $component)
+ @include('partials.component_input', compact($component))
+ @endforeach
+
+ @endif
+
+@endforeach
+@endif
+
+@if($ungrouped_components->count() > 0)
+
+ -
+ {{ trans('cachet.components.group.other') }}
+
+ @foreach($ungrouped_components as $component)
+ @include('partials.component_input', compact($component))
+ @endforeach
+
+@endif
diff --git a/resources/views/subscribe/manage.blade.php b/resources/views/subscribe/manage.blade.php
index 0069dfcbc29e..df442b88dacc 100644
--- a/resources/views/subscribe/manage.blade.php
+++ b/resources/views/subscribe/manage.blade.php
@@ -1,6 +1,7 @@
@extends('layout.master')
@section('content')
+
@@ -17,43 +18,24 @@
Manage notifications for {{ $subscriber->email }}
- @if($components->count() > 0)