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..8cfb857520ab 100644 --- a/app/Presenters/ComponentGroupPresenter.php +++ b/app/Presenters/ComponentGroupPresenter.php @@ -97,4 +97,27 @@ 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..4ac6dc4de733 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -277,6 +277,24 @@ $(function() { $this.next('.group-items').toggleClass('hide'); }); + $('.select-group').on('click', function () { + 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 $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..599d525ef8d8 --- /dev/null +++ b/resources/views/partials/component_input.blade.php @@ -0,0 +1,17 @@ +
  • +
    + +
    + @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..2c260d70fdb4 --- /dev/null +++ b/resources/views/partials/components_form.blade.php @@ -0,0 +1,33 @@ +@if($component_groups->count() > 0) + @foreach($component_groups as $componentGroup) + + @endforeach +@endif + +@if($ungrouped_components->count() > 0) + +@endif diff --git a/resources/views/subscribe/manage.blade.php b/resources/views/subscribe/manage.blade.php index 0069dfcbc29e..3bcade126f8c 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)
    {{ trans('cachet.subscriber.manage.my_subscriptions') }}
    -
    - @foreach($components as $component) -
    -
    - -
    -
    - @endforeach +
    + @if(!$component_groups->isEmpty() || !$ungrouped_components->isEmpty()) + @include('partials.components_form') + @else +

    {{ trans('cachet.subscriber.manage.no_subscriptions') }}

    + @endif
    - @else -
    -
    -

    {{ trans('cachet.subscriber.manage.no_subscriptions') }}

    -
    -
    - @endif
    @stop