Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nateiler committed Jul 25, 2018
2 parents b8b270b + 5ceb2fd commit 5d5c194
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 112 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,10 @@
Changelog
=========
## 1.0.0-rc.23 - 2018-07-25
### Added
- User type association HUD is grouped by source headings
- Sidebar navigation to easily get to/from settings and elements

## 1.0.0-rc.22 - 2018-07-06
### Added
- Organization Type field type can customize the drop down first option
Expand Down
2 changes: 1 addition & 1 deletion composer.json
@@ -1,7 +1,7 @@
{
"name": "flipboxfactory/organizations",
"description": "Simple parent + child management",
"version": "1.0.0-rc.22",
"version": "1.0.0-rc.23",
"type": "craft-plugin",
"keywords": [
"flipbox",
Expand Down
34 changes: 34 additions & 0 deletions src/Organizations.php
Expand Up @@ -186,6 +186,40 @@ protected static function getLogFileName(): string
return 'organizations';
}

/*******************************************
* NAV
*******************************************/

/**
* @inheritdoc
*/
public function getCpNavItem()
{
return array_merge(
parent::getCpNavItem(),
[
'subnav' => [
'organizations.organizations' => [
'label' => Craft::t('organizations', 'Organizations'),
'url' => 'organizations'
],
'organizations.general' => [
'label' => Craft::t('organizations', 'Settings'),
'url' => 'organizations/settings'
],
'organizations.organization-types' => [
'label' => Craft::t('organizations', 'Organization Types'),
'url' => 'organizations/settings/organization-types',
],
'organizations.user-types' => [
'label' => Craft::t('organizations', 'User Types'),
'url' => 'organizations/settings/user-types',
]
]
]
);
}

/*******************************************
* EVENTS
*******************************************/
Expand Down
35 changes: 30 additions & 5 deletions src/cp/controllers/UserTypesController.php
Expand Up @@ -9,8 +9,8 @@
namespace flipbox\organizations\cp\controllers;

use Craft;
use craft\elements\User;
use craft\helpers\ArrayHelper;
use flipbox\organizations\db\UserTypeQuery;
use flipbox\organizations\Organizations;
use yii\web\Response;

Expand Down Expand Up @@ -121,15 +121,40 @@ public function actionGetEditorHtml(): Response
[
'user' => $user,
'organization' => $organization,
'types' => (new UserTypeQuery([
'organization' => $organization->id,
'user' => $user->id
]))->all()
'typeOptions' => $this->getUserTypes()
]
);
$response['headHtml'] = $view->getHeadHtml();
$response['footHtml'] = $view->getBodyHtml();

return $this->asJson($response);
}

/**
* @return array
*/
private function getUserTypes(): array
{
$types = Organizations::getInstance()->getUserTypes()->getQuery()
->select(['name'])
->indexBy('id')
->column();

$lastHeading = null;
$items = [];
foreach (Craft::$app->getElementIndexes()->getSources(User::class) as $source) {
if (array_key_exists('heading', $source)) {
$lastHeading = $source['heading'];
continue;
}

$label = $source['label'] ?? null;

if ($label !== null && in_array($label, $types, true)) {
$items[$lastHeading][array_search($label, $types)] = $label;
}
}

return $items;
}
}
6 changes: 6 additions & 0 deletions src/cp/controllers/settings/view/AbstractController.php
Expand Up @@ -57,6 +57,12 @@ protected function baseVariables(array &$variables = [])
{
parent::baseVariables($variables);

// Select our sub-nav
if (!$activeSubNav = Craft::$app->getRequest()->getSegment(3)) {
$activeSubNav = 'general';
}
$variables['selectedSubnavItem'] = 'organizations.' . $activeSubNav;

$title = Craft::t('organizations', "Settings");
$variables['title'] = Craft::t('organizations', "Organization") . ' ' . $title;

Expand Down
3 changes: 3 additions & 0 deletions src/cp/controllers/view/AbstractController.php
Expand Up @@ -82,6 +82,9 @@ protected function baseVariables(array &$variables = [])
// Set the "Continue Editing" URL
$variables['continueEditingUrl'] = $this->getBaseCpPath();

// Select our sub-nav
$variables['selectedSubnavItem'] = 'organizations.organizations';

// Breadcrumbs
$variables['crumbs'][] = [
'label' => $title,
Expand Down
26 changes: 12 additions & 14 deletions src/templates/_components/fieldtypes/OrganizationType/input.twig
Expand Up @@ -4,18 +4,16 @@
label: 'Select Organization Type'|t('organizations'),
value: null
}] %}
{#{% for type in craft.organizations.organizationTypes.query.all() %}#}
{#{% set typeOptions = typeOptions|merge([{#}
{#label: type.name,#}
{#value: type.id#}
{#}]) %}#}
{#{% endfor %}#}
{% for type in craft.organizations.organizationTypes.query.all() %}
{% set typeOptions = typeOptions|merge([{
label: type.name,
value: type.id
}]) %}
{% endfor %}

{{ dump(value) }}

{#{{ forms.select({#}
{#id: field.handle,#}
{#name: field.handle,#}
{#value: value ? value.id : null,#}
{#options: typeOptions#}
{#}) }}#}
{{ forms.select({
id: field.handle,
name: field.handle,
value: value ? value.id : null,
options: typeOptions
}) }}
31 changes: 17 additions & 14 deletions src/templates/_cp/_components/userTypesEditorHtml.twig
@@ -1,20 +1,23 @@
{% import "_includes/forms" as forms %}
<div class="meta">
{% set selectedTypeIds = [] %}
{% for type in types %}
{% set selectedTypeIds = selectedTypeIds|merge([type.id]) %}
{% endfor %}
<div class="meta user-types-hud">
{% set selectedTypes = craft.organizations.userTypes.getQuery({
organization: organization,
user: user,
select: ['typeId']
}).column() %}

{% namespace 'types' %}
{% for userType in craft.organizations.userTypes.findAll() %}
{% set selected = userType.id in selectedTypeIds %}
{{ forms.lightswitchField({
label: userType.name|t('organizations'),
id: userType.handle,
name: userType.id,
on: selected,
}) }}
{% for heading, types in typeOptions %}
{% if heading %}<h6 class="group-heading">{{ heading }}</h6>{% endif %}
{% for id, label in types %}
{% set selected = id in selectedTypes %}
{{ forms.lightswitchField({
label: label|t('organizations'),
id: id,
name: id,
on: selected,
}) }}
{% endfor %}
{% endfor %}
{% endnamespace %}
</div>

27 changes: 1 addition & 26 deletions src/templates/_cp/settings/_layout.twig
@@ -1,26 +1 @@
{% extends "_layouts/cp" %}
{% block sidebar %}
{% set baseCpPath = 'organizations/settings' %}
{% set selected = selected is defined ? selected : craft.app.request.getSegment(3) %}
{% set nav = {
general : {
label: 'General',
uri: ''
},organizationTypes : {
label: 'Organization Types',
uri: 'organization-types'
},userTypes : {
label: 'User Types',
uri: 'user-types'
}
} %}
<nav>
<ul>
<li class="heading"><span>Navigation</span></li>
{% for navKey, navItem in nav %}
<li><a tabindex="0"{% if selected == navItem.uri %} class="sel"{% endif %}
href="{{ url(baseCpPath ~ (navItem.uri ? '/'~navItem.uri : '')) }}">{{ navItem.label }}</a></li>
{% endfor %}
</ul>
</nav>
{% endblock %}
{% extends "_layouts/cp" %}
70 changes: 27 additions & 43 deletions src/web/assets/organization/dist/css/Organization.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions src/web/assets/organization/dist/css/Organization.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion src/web/assets/organization/src/Organization.scss
@@ -1,5 +1,5 @@
@charset "UTF-8";
@import "../../../../../../../vendor/craftcms/cms/lib/craftcms-sass/mixins";
@import "../../../../../vendor/craftcms/cms/lib/craftcms-sass/mixins";

/* ----------------------------------------
/* Organization
Expand All @@ -21,6 +21,22 @@

}

.user-types-hud {

.group-heading {
margin-bottom: 0;
text-transform: uppercase;
font-size: 12px;

}

.field {
padding-right: 36px;

}

}

/* delete organization modal */
.deleteorganizationmodal,
.changeorganizationstatusmodal {
Expand Down

0 comments on commit 5d5c194

Please sign in to comment.