Skip to content

Commit

Permalink
Move revision settings to catalog (#1544)
Browse files Browse the repository at this point in the history
* Move revision settings to catalog

Added a package in core for catalog.
Added settings panel for catalog.
Updated registry entries for revisions to appear in catalog settings
panel.
Updated UI for registry settings card.

* added key for i18n
  • Loading branch information
mikemurray authored and Aaron Judd committed Nov 1, 2016
1 parent 7a6e508 commit d9cf9df
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 75 deletions.
2 changes: 2 additions & 0 deletions imports/plugins/core/catalog/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "./templates/settings.html";
import "./templates/settings.js"
19 changes: 19 additions & 0 deletions imports/plugins/core/catalog/client/templates/settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template name="catalogSettings">
{{#each reactionApps provides='catalogSettings'}}
<div class="panel panel-default">
<div class="panel-heading panel-heading-flex">
<div class="panel-title">
<i class="fa fa-{{name}}"></i>
<span data-i18n="{{i18nKeyLabel}}">{{label}}</span>

</div>
<div class="panel-controls">
<input class="checkbox-switch" type="checkbox" value={{name}} name="enabled" data-id="{{packageId}}" {{checked .}}>
</div>
</div>
<div class="panel-body {{shown .}}">
{{> Template.dynamic template=template data=.}}
</div>
</div>
{{/each}}
</template>
53 changes: 53 additions & 0 deletions imports/plugins/core/catalog/client/templates/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Packages } from "/lib/collections";

Template.catalogSettings.helpers({
//
// check if this package setting is enabled
//
checked(pkg) {
let enabled;
const pkgData = Packages.findOne(pkg.packageId);
const setting = pkg.name.split("/").splice(-1);

if (pkgData && pkgData.settings) {
if (pkgData.settings[setting]) {
enabled = pkgData.settings[setting].enabled;
}
}
return enabled === true ? "checked" : "";
},
//
// Template helper to add a hidden class if the condition is false
//
shown(pkg) {
let enabled;
const pkgData = Packages.findOne(pkg.packageId);
const setting = pkg.name.split("/").splice(-1);

if (pkgData && pkgData.settings) {
if (pkgData.settings[setting]) {
enabled = pkgData.settings[setting].enabled;
}
}

return enabled !== true ? "hidden" : "";
}
});

Template.catalogSettings.events({
/**
* taxSettings settings update enabled status for tax service on change
* @param {event} event jQuery Event
* @return {void}
*/
"change input[name=enabled]": (event) => {
const name = event.target.value;
const packageId = event.target.getAttribute("data-id");
const fields = [{
property: "enabled",
value: event.target.checked
}];

Meteor.call("registry/update", packageId, name, fields);
}
});
27 changes: 27 additions & 0 deletions imports/plugins/core/catalog/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Reaction } from "/server/api";

Reaction.registerPackage({
label: "Catalog",
name: "reaction-catalog",
icon: "fa fa-archive",
autoEnable: true,
settings: {
name: "Catalog"
},
registry: [
{
provides: "dashboard",
label: "Catalog",
description: "Product catalog",
icon: "fa fa-archive",
priority: 2,
container: "core"
},
{
label: "Catalog Settings",
name: "catalog/settings",
provides: "settings",
template: "catalogSettings"
}
]
});
50 changes: 21 additions & 29 deletions imports/plugins/core/revisions/client/components/settings.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@
import React, { Component, PropTypes } from "react";
import {
Card,
CardHeader,
CardBody,
Checkbox
} from "/imports/plugins/core/ui/client/components";
import _set from "lodash/set";
import { Translation } from "/imports/plugins/core/ui/client/components";


class RevisionControlSettings extends Component {
get settings() {
return this.props.settings;
}

handleChange = (event, value, fieldName) => {
if (this.props.onUpdateSettings) {
const settingsCopy = Object.assign({}, this.props.settings);
_set(settingsCopy, fieldName, value);
this.props.onUpdateSettings(settingsCopy);
render() {
let message;

if (this.settings.general.enabled) {
message = (
<Translation
defaultValue="Revision controls is enabled"
i18nKey="revisions.isEnabled"
/>
);
} else {
message = (
<Translation
defaultValue="Revision controls is disabled"
i18nKey="revisions.isDisabled"
/>
);
}
}

render() {
return (
<Card className="rui publish-controls">
<CardHeader
i18nKeyTitle="revisions.general"
title="General"
/>
<CardBody>
<Checkbox
checked={this.settings.general.enabled}
i18nKeyLabel="revisions.enableRevisionControl"
label="Enable revision control"
name="general.enabled"
onChange={this.handleChange}
/>
</CardBody>
</Card>
<div className="rui publish-controls">
<p className="help-text">{message}</p>
</div>
);
}
}
Expand Down
18 changes: 4 additions & 14 deletions imports/plugins/core/revisions/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@ Reaction.registerPackage({
}
},
registry: [
// Dashboard card
// Settings Panel in Catalog
{
provides: "dashboard",
label: "Revisions",
description: "Revision control",
icon: "fa fa-undo",
priority: 2,
container: "core"
},
// Settings Panel
{
label: "Revision Settings",
route: "/dashboard/revisions",
provides: "settings",
container: "dashboard",
label: "Product Revisions",
name: "catalog/settings/revisions/general",
provides: "catalogSettings",
template: "revisionControlSettings"
}
]
Expand Down
2 changes: 2 additions & 0 deletions private/data/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"examplePaymentSettingsLabel": "Example Payment Settings",
"productSettingsLabel": "Product Settings",
"productDetailsLabel": "Product Details",
"productRevisionsLabel": "Product Revisions",
"taxSettingsLabel": "Tax Settings"
},
"userAccountDropdown": {
Expand Down Expand Up @@ -579,6 +580,7 @@
},
"revisions": {
"isDisabled": "Revision control is disabled. Any changes will be published immediately.",
"isEnabled": "Revision control is enabled for Products. Any changes will be need to be published before being visible to customers.",
"unpublishedChanges": "Unpublished Changes",
"publishChanges": "Publish Changes",
"showChanges": "Show Changes",
Expand Down
30 changes: 0 additions & 30 deletions server/startup/registry/catalog.js

This file was deleted.

2 changes: 0 additions & 2 deletions server/startup/registry/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import Accounts from "./accounts";
import Catalog from "./catalog";
import Core from "./core";
import i18n from "./i18n";
import Router from "./router";

export default function () {
Accounts();
Catalog();
Core();
i18n();
Router();
Expand Down

0 comments on commit d9cf9df

Please sign in to comment.