billy_cms 0.0.11 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 619314e33692f6ce71b51ade84cdc51d0903c5d5
4
- data.tar.gz: 2fe41171a67e95a210ba083fc5e6116087cd633f
3
+ metadata.gz: 1dd64aeeedb98f763d5cefcaada670b0fe5c4798
4
+ data.tar.gz: fe8743b1229d9ba5e3a0797c02cc612eecc36953
5
5
  SHA512:
6
- metadata.gz: 0b229af480394c3be2e069c97b10de2e9b3f19c837bbb01a18d503b78d73d08b6739b27f7b4b87b5548b8e02725fd2ef36eab1aaaa9527bb44fcf8f7610abdc9
7
- data.tar.gz: 732487a213014d6b4bed97e20d4184a9d7f8fc28a7ece74d4187b3f0af4db4bcd45281300bca9ec63a25bc957ffb6c8bf4049747748e6e7e9145c6be91a203e3
6
+ metadata.gz: 658d41360662fbcb6c027b2df5004501499b7a913a8f1131e1140459b21aa40059b2906d22b6cedec2ce6ee1a76d24f92bc78788a7c07714127b956965a239d1
7
+ data.tar.gz: bc75818c778befa9b4e70a67f789bd3fbb4e5e44380b37b5dd662f0cd2101c7d62d977106a324ec05ee8014266f22716ec835d30e17d7dc1b2c2f8ccd2864bfe
@@ -31,6 +31,6 @@ angular.module('BillyCmsBackend',
31
31
  .state('additional_attributes', {
32
32
  url: '/system/attributes',
33
33
  templateUrl: 'attributes/attributes.html',
34
- controller: 'AttributesCtrl as attrs'
34
+ controller: 'AttributesCtrl as atctrl'
35
35
  })
36
36
  });
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ angular.module('BillyCmsBackend').controller('AttributesCtrl', ['$scope', '$http', 'AdditionalAttribute', function($scope, $http, AdditionalAttribute) {
4
+ var self = this;
5
+
6
+ this.selectedTabIndex = 0;
7
+
8
+ this.resetNewAttribute = function() {
9
+ this.newAttribute = new AdditionalAttribute();
10
+ };
11
+ this.resetNewAttribute();
12
+
13
+ this.createAttribute = function() {
14
+ $http.post('/billy_cms/api/attributes.json', this.newAttribute)
15
+ .then(function(result) {
16
+ var attribute = new AdditionalAttribute(result.data.attribute);
17
+ $scope.app.allAdditionalAttributes.push(attribute);
18
+
19
+ self.selectedTabIndex = 0;
20
+ })
21
+ .catch(function(err) {
22
+ alert(err);
23
+ })
24
+ }
25
+
26
+ return this;
27
+ }]);
@@ -1,3 +1,5 @@
1
+ 'use strict';
2
+
1
3
  window.angular.module('BillyCmsBackend').controller('PageTypesCtrl', ['$scope', function($scope) {
2
4
  var self = this;
3
5
  $scope.$watch(
@@ -16,4 +18,37 @@ window.angular.module('BillyCmsBackend').controller('PageTypesCtrl', ['$scope',
16
18
  if ($scope.app.allPageTypes && $scope.app.allPageTypes.length > 0) {
17
19
  this.selectPageType($scope.app.allPageTypes[0]);
18
20
  }
21
+
22
+ this.addAtributeToSelectedPageType = function() {
23
+ var attributeId = this.attributeIdToAdd;
24
+ var pageType = this.selectedPageType;
25
+ if (!pageType) {
26
+ return console.error('No Page Type selected.');
27
+ }
28
+ return pageType
29
+ .addAdditionalAttribute(attributeId)
30
+ .then(function() {
31
+ self.attributeIdToAdd = null;
32
+ })
33
+ .catch(function(error) {
34
+ alert(error);
35
+ });
36
+ };
37
+
38
+ this.removeAttribute = function(attribute) {
39
+ return this.selectedPageType.removeAdditionalAttribute(attribute).catch(function(err) {
40
+ alert(err);
41
+ });
42
+ }
43
+
44
+ this.attributesAddableToSelectedPageType = function() {
45
+ if (!self.selectedPageType) {
46
+ return [];
47
+ }
48
+ return ($scope.app.allAdditionalAttributes || []).filter(function(attribute) {
49
+ return self.selectedPageType.additional_attributes
50
+ .map(function(attr) { return attr.id; })
51
+ .indexOf(attribute.id) < 0;
52
+ });
53
+ }
19
54
  }]);
@@ -2,6 +2,7 @@
2
2
 
3
3
  angular.module('BillyCmsBackend').factory('AdditionalAttribute', [function() {
4
4
  var AdditionalAttribute = function(options) {
5
+ if (!options) { options = {} }
5
6
  this.id = options.id || null;
6
7
  this.name = options.name || null;
7
8
  this.title = options.title || '';
@@ -1,17 +1,62 @@
1
1
  'use strict';
2
2
 
3
- angular.module('BillyCmsBackend').factory('PageType', ['AdditionalAttribute', function(AdditionalAttribute) {
3
+ angular.module('BillyCmsBackend').factory('PageType', ['AdditionalAttribute', '$http', function(AdditionalAttribute, $http) {
4
4
  var PageType = function(options) {
5
- this.id = options.id || null;
6
- this.name = options.name || null;
7
- this.title = options.title || '';
8
-
9
- this.additional_attributes = (options.additional_attributes || []).map(function(attributeOptions) {
10
- return new AdditionalAttribute(attributeOptions);
11
- })
5
+ this.applyOptions(options);
12
6
  };
13
7
 
8
+ PageType.prototype.applyOptions = function(options) {
9
+ this.id = options.id || null;
10
+ this.name = options.name || null;
11
+ this.title = options.title || '';
12
+
13
+ this.additional_attributes = (options.additional_attributes || []).map(function(attributeOptions) {
14
+ return new AdditionalAttribute(attributeOptions);
15
+ })
16
+ }
17
+
18
+ PageType.prototype.addAdditionalAttribute = function(attributeOrAttributeId) {
19
+ var attributeId;
20
+ var self = this;
21
+ if (!this.id) {
22
+ throw new Error('PageType is not valid.');
23
+ }
24
+ if (typeof attributeOrAttributeId === 'number' || typeof attributeOrAttributeId === 'string') {
25
+ attributeId = parseInt(attributeOrAttributeId, 10);
26
+ } else {
27
+ attributeId = attributeOrAttributeId.id;
28
+ }
29
+ if (!attributeId) {
30
+ throw new Error('Please pass a valid attribute or attribute id.');
31
+ }
32
+ return $http.post('/billy_cms/api/page_types/' + String(this.id) + '/attributes.json', {
33
+ attribute: {
34
+ id: attributeId
35
+ }
36
+ }).then(function(result) {
37
+ self.applyOptions(result.data.page_type)
38
+ });
39
+ }
14
40
 
41
+ PageType.prototype.removeAdditionalAttribute = function(attributeOrAttributeId) {
42
+ var self = this;
43
+ var attributeId;
44
+ if (!this.id) {
45
+ throw new Error('PageType is not valid.');
46
+ }
47
+ if (typeof attributeOrAttributeId === 'number' || typeof attributeOrAttributeId === 'string') {
48
+ attributeId = parseInt(attributeOrAttributeId, 10);
49
+ } else {
50
+ attributeId = attributeOrAttributeId.id;
51
+ }
52
+ if (!attributeId) {
53
+ throw new Error('Please pass a valid attribute or attribute id.');
54
+ }
55
+ return $http.delete('/billy_cms/api/page_types/' + String(this.id) + '/attributes/' + String(attributeId))
56
+ .then(function(result) {
57
+ self.applyOptions(result.data.page_type)
58
+ });
59
+ }
15
60
 
16
61
  return PageType;
17
62
 
@@ -18,4 +18,17 @@ i.jstree-icon.binary-type {
18
18
 
19
19
  md-list-item.selected {
20
20
  border-left: 5px mediumslateblue ridge;
21
+ }
22
+
23
+ span.delete-link {
24
+ color: #730E15;
25
+ ::before {
26
+ content: '[';
27
+ }
28
+ ::after {
29
+ content: ']';
30
+ }
31
+ &:hover {
32
+ color: #ff1e2e;
33
+ }
21
34
  }
@@ -11,7 +11,7 @@ module Api
11
11
  def update
12
12
  render nothing: true, status: 400 unless params[:attribute]
13
13
  attribute = BillyCms::AdditionalAttribute.find params[:id]
14
- if attribute.update_attributes attribute_params
14
+ if attribute.update_attributes attributes_params
15
15
  render json: {
16
16
  success: true,
17
17
  attribute: attribute
@@ -26,7 +26,7 @@ module Api
26
26
 
27
27
  def create
28
28
  render nothing: true, status: 400 unless params[:attribute]
29
- attribute = BillyCms::AdditionalAttribute.new attribute_params
29
+ attribute = BillyCms::AdditionalAttribute.new attributes_params
30
30
  if attribute.save
31
31
  render json: {
32
32
  success: true,
@@ -57,7 +57,7 @@ module Api
57
57
  private
58
58
 
59
59
  def attributes_params
60
- params.require(:attribute).permit(:title, :attribute, :attribute_type) if current_user.admin?
60
+ params.require(:attribute).permit(:title, :name, :attribute_type) if current_user.admin?
61
61
  end
62
62
  end
63
63
  end
@@ -0,0 +1,59 @@
1
+ module Api
2
+ class PageTypeAttributesController < ApiController
3
+ before_filter :set_page_type
4
+ before_filter :set_additional_attribute, only: [:create]
5
+ before_filter :ensure_user_is_admin
6
+
7
+ def index
8
+ render json: @page_type.additional_attributes
9
+ end
10
+
11
+ def show
12
+ render json: @page_type.additional_attributes.find(params.fetch(:id))
13
+ end
14
+
15
+ def create
16
+ if @page_type && @additional_attribute
17
+ if @page_type.additional_attributes.include? @additional_attribute
18
+ render json: { success: false, error: 'Attribute already exists.' }, status: 400
19
+ else
20
+ @page_type.additional_attributes.push @additional_attribute
21
+ render json: { success: true, page_type: BillyCms::PageTypeSerializer.new(@page_type) }
22
+ end
23
+ end
24
+ end
25
+
26
+ def destroy
27
+ additional_attribute_id = params[:id]
28
+ @additional_attribute = BillyCms::AdditionalAttribute.find(additional_attribute_id)
29
+ if @page_type && @additional_attribute
30
+ unless @page_type.additional_attributes.include? @additional_attribute
31
+ render json: { success: false, error: "Attribute does not exist on pages of type '#{@page_type.name}'." }, status: 400
32
+ else
33
+ @page_type.additional_attributes.delete(additional_attribute_id)
34
+ render json: { success: true, page_type: BillyCms::PageTypeSerializer.new(@page_type) }
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def set_page_type
42
+ @page_type = BillyCms::PageType.find(params.fetch(:page_type_id))
43
+ end
44
+
45
+ def set_additional_attribute
46
+ if id = attribute_params[:id]
47
+ begin
48
+ @additional_attribute = BillyCms::AdditionalAttribute.find id
49
+ rescue ActiveRecord::RecordNotFound
50
+ @additional_attribute = nil
51
+ end
52
+ end
53
+ end
54
+
55
+ def attribute_params
56
+ params.require(:attribute).permit(:id)
57
+ end
58
+ end
59
+ end
@@ -3,7 +3,14 @@ module BillyCms
3
3
 
4
4
  def page_field(page, field, options = {})
5
5
  tag_name = options[:tag] || :div
6
- content_tag tag_name, page.send(field).to_s.html_safe, class: "page-#{field.to_s}", 'billycms-attribute' => field.to_s, 'billycms-page' => page[:id], contenteditable: false
6
+ html_options = {
7
+ :'billycms-attribute' => field.to_s,
8
+ :'billycms-page' => page[:id],
9
+ :contenteditable => false,
10
+ :class => ''
11
+ }.merge(options[:html] || {})
12
+ html_options[:class] += " page-#{field.to_s}"
13
+ content_tag tag_name, page.send(field).to_s.html_safe, html_options
7
14
  end
8
15
 
9
16
  def cms_image(obj, options = {})
@@ -1,12 +1,39 @@
1
1
  <md-content>
2
- <h2>Attribute</h2>
2
+ <md-tabs md-dynamic-height md-border-bottom md-selected="atctrl.selectedTabIndex">
3
+ <md-tab label="Alle Attribute">
4
+ <md-list>
5
+ <md-list-item class="md-2-line" ng-repeat="attribute in app.allAdditionalAttributes">
6
+ <div class="md-list-item-text" layout="column">
7
+ <h3>{{ attribute.title }}</h3>
8
+ <p>{{ attribute.name }} &bull; {{attribute.attribute_type}}</p>
9
+ </div>
10
+ </md-list-item>
11
+ </md-list>
12
+ </md-tab>
13
+ <md-tab label="Neues Attribut hinzufügen">
14
+ <form ng-submit="atctrl.createAttribute()">
15
+ <md-input-container class="md-block">
16
+ <label>Titel:</label>
17
+ <input type="text" ng-model="atctrl.newAttribute.title" />
18
+ </md-input-container>
19
+ <md-input-container class="md-block">
20
+ <label>Name:</label>
21
+ <input type="text" ng-model="atctrl.newAttribute.name" />
22
+ </md-input-container>
23
+ <md-input-container class="md-block">
24
+ <label>Typ:</label>
25
+ <md-select ng-model="atctrl.newAttribute.attribute_type">
26
+ <md-option value="string">Text</md-option>
27
+ <md-option value="integer">Zahl</md-option>
28
+ <md-option value="email">Email</md-option>
29
+ <md-option value="url">URL</md-option>
30
+ </md-select>
31
+ </md-input-container>
3
32
 
4
- <md-list>
5
- <md-list-item class="md-2-line" ng-repeat="attribute in attrs.possibleAttributes">
6
- <div class="md-list-item-text" layout="column">
7
- <h3>{{ attribute.title }}</h3>
8
- <p>{{ attribute.name }} &bull; {{attribute.attribute_type}}</p>
33
+ <div layout="row">
34
+ <input type="submit" value="speichern" class="md-button md-primary md-raised" />
9
35
  </div>
10
- </md-list-item>
11
- </md-list>
36
+ </form>
37
+ </md-tab>
38
+ </md-tabs>
12
39
  </md-content>
@@ -34,14 +34,16 @@
34
34
  Zusätzliche Eigenschaften
35
35
  </h2>
36
36
  <md-input-container>
37
- <label>Hinzufügen:</label>
38
- <md-select ng-model="ptctrl.attributeToAdd">
39
- <md-option ng-repeat="attribute in app.allAdditionalAttributes" value="{{attribute}}">{{attribute.title}}</md-option>
37
+ <label>Mögliche zusätzliche Eigenschaft hinzufügen:</label>
38
+ <md-select ng-model="ptctrl.attributeIdToAdd" ng-change="ptctrl.addAtributeToSelectedPageType()">
39
+ <md-option ng-repeat="attribute in ptctrl.attributesAddableToSelectedPageType() track by $index" value="{{attribute.id}}">
40
+ {{attribute.title}} ({{attribute.name}})
41
+ </md-option>
40
42
  </md-select>
41
43
  </md-input-container>
42
44
  <ul>
43
45
  <li ng-repeat="attribute in ptctrl.selectedPageType.additional_attributes">
44
- {{attribute.title}}
46
+ {{attribute.title}} &nbsp; <span class="delete-link" ng-click="ptctrl.removeAttribute(attribute)">entfernen</span>
45
47
  </li>
46
48
  </ul>
47
49
  </form>
data/config/routes.rb CHANGED
@@ -3,6 +3,8 @@ BillyCms::Engine.routes.draw do
3
3
  namespace :api do
4
4
  resources :pages
5
5
  resources :attributes
6
- resources :page_types
6
+ resources :page_types do
7
+ resources :attributes, controller: :page_type_attributes, only: [:index, :show, :create, :destroy]
8
+ end
7
9
  end
8
10
  end
@@ -1,3 +1,3 @@
1
1
  module BillyCms
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.14"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: billy_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - unsdrei GbR
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-15 00:00:00.000000000 Z
11
+ date: 2016-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,12 +126,12 @@ files:
126
126
  - app/assets/javascripts/billy_cms.js
127
127
  - app/assets/javascripts/billy_cms/backend.js
128
128
  - app/assets/javascripts/billy_cms/backend/app.js.erb
129
- - app/assets/javascripts/billy_cms/backend/attributes.js
130
129
  - app/assets/javascripts/billy_cms/backend/controllers/application.controller.js.erb
130
+ - app/assets/javascripts/billy_cms/backend/controllers/attributes.controller.js
131
131
  - app/assets/javascripts/billy_cms/backend/controllers/page_types.controller.js
132
132
  - app/assets/javascripts/billy_cms/backend/directives/header.directive.js
133
133
  - app/assets/javascripts/billy_cms/backend/directives/ng-jstree.js
134
- - app/assets/javascripts/billy_cms/backend/factories/additional_attribute.js
134
+ - app/assets/javascripts/billy_cms/backend/factories/additional_attribute.factory.js
135
135
  - app/assets/javascripts/billy_cms/backend/factories/billy_object.js
136
136
  - app/assets/javascripts/billy_cms/backend/factories/page_type.js
137
137
  - app/assets/javascripts/billy_cms/backend/jstree.js
@@ -149,6 +149,7 @@ files:
149
149
  - app/assets/stylesheets/billy_cms/jstree.scss
150
150
  - app/controllers/api/api_controller.rb
151
151
  - app/controllers/api/attributes_controller.rb
152
+ - app/controllers/api/page_type_attributes_controller.rb
152
153
  - app/controllers/api/page_types_controller.rb
153
154
  - app/controllers/api/pages_controller.rb
154
155
  - app/controllers/billy_cms/backend_controller.rb
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- angular.module('BillyCmsBackend').controller('AttributesCtrl', function($http, Attribute) {
4
- var vm = this;
5
-
6
- vm.possibleAttributes = [];
7
- vm.loadAttributes = function() {
8
- $http.get('/billy_cms/api/attributes')
9
- .then(function(response) {
10
- var data = response.data;
11
- console.log(data);
12
- vm.possibleAttributes = data.attributes.map(function(attr) {
13
- return new Attribute(attr);
14
- })
15
- }, function(err) {
16
- alert('Fehler: ', err);
17
- });
18
- };
19
- vm.loadAttributes();
20
-
21
- return vm;
22
- });
23
-
24
- angular.module('BillyCmsBackend').factory('Attribute', function() {
25
- var Attribute = function(options) {
26
- this.title = options.title || '';
27
- this.name = options.name || null;
28
- this.id = options.id || null;
29
- this.attribute_type = options.attribute_type || 'string';
30
- };
31
-
32
- return Attribute;
33
- });