Skip to content
This repository has been archived by the owner on Jul 26, 2020. It is now read-only.

Commit

Permalink
Renames Items to Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Oct 15, 2014
1 parent 16b1015 commit 88254ce
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 141 deletions.
3 changes: 1 addition & 2 deletions client/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<script src="bower_components/angular-touch/angular-touch.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="bower_components/angular-formly/dist/formly.bootstrap.min.js"></script>
<script src="bower_components/angular-formly/dist/formly.bootstrap.min.map"></script>
<script src="bower_components/angular-toasty/js/ng-toasty.js"></script>
<script src="bower_components/angular-file-upload/angular-file-upload.js"></script>
<!-- endbower -->
Expand All @@ -60,7 +59,7 @@
<script src="scripts/directives/register.js"></script>
<script src="scripts/services/appauth.js"></script>
<script src="scripts/directives/home.js"></script>
<script src="scripts/controllers/items.js"></script>
<script src="scripts/controllers/pages.js"></script>
<script src="scripts/controllers/users.js"></script>
<script src="scripts/controllers/sandbox.js"></script>
<script src="scripts/controllers/notes.js"></script>
Expand Down
113 changes: 0 additions & 113 deletions client/app/scripts/controllers/items.js

This file was deleted.

4 changes: 2 additions & 2 deletions client/app/scripts/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ angular.module('loopbackApp')
sref: 'app.events.list',
icon: 'fa-calendar-o'
} , {
name: 'Items',
sref: 'app.items.list',
name: 'Pages',
sref: 'app.pages.list',
icon: 'fa-file-o'
} , {
name: 'Notes',
Expand Down
120 changes: 120 additions & 0 deletions client/app/scripts/controllers/pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
'use strict';

/**
* @ngdoc function
* @name loopbackApp.controller:PagesCtrl
* @description
* # PagesCtrl
* Controller of the loopbackApp
*/
angular.module('loopbackApp')
.config(function($stateProvider) {
$stateProvider.state('app.pages', {
abstract: true,
url: '/pages',
templateUrl: 'views/pages/main.html',
controller: 'PagesCtrl'
})
.state('app.pages.list', {
url: '',
templateUrl: 'views/pages/list.html',
controller: 'PagesCtrl'
})
.state('app.pages.add', {
url: '/add',
templateUrl: 'views/pages/form.html',
controller: 'PagesCtrl'
})
.state('app.pages.edit', {
url: '/:id/edit',
templateUrl: 'views/pages/form.html',
controller: 'PagesCtrl'
})
.state('app.pages.view', {
url: '/:id',
templateUrl: 'views/pages/view.html',
controller: 'PagesCtrl'
});
})

.controller('PagesCtrl', function($scope, $state, $stateParams, toasty, Page) {

var pageId = $stateParams.id;

if (pageId) {
$scope.page = Page.findById({
id: pageId
}, function() {}, function(err) {
console.log(err);
});
} else {
$scope.page = {};
}

function loadPages() {
$scope.pages = Page.find();
}

loadPages();

$scope.delete = function(id) {
// if (confirm('Are you sure?') === false) {
// return false;
// }
Page.deleteById(id, function() {
toasty.pop.success({title: 'Page deleted', msg: 'Your page is deleted!', sound: false});
loadPages();
$state.go('app.pages.list');
console.log();
}, function(err) {
toasty.pop.error({title: 'Error deleting page', msg: 'Your page is not deleted: ' + err, sound: false});
});

};

$scope.formFields = [{
key: 'name',
label: 'Name',
type: 'text',
required: true
}, {
key: 'slug',
label: 'Slug',
type: 'text'
}, {
key: 'content',
label: 'Content',
type: 'textarea'
}, {
key: 'extended',
label: 'Extended content',
type: 'textarea'
}];

$scope.formOptions = {

//Set the id of the form
uniqueFormId: true,

//Hide the submit button that is added automaticaly
//default: false
hideSubmit: false,

//Set the text on the default submit button
//default: Submit
submitCopy: 'Save'
};

$scope.onSubmit = function() {

Page.upsert($scope.page, function() {
toasty.pop.success({title: 'Page saved', msg: 'Your page is safe with us!', sound: false});
$state.go('^.list');
}, function(err) {
console.log(err);
});

};


});
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<h4>
<a href="" ui-sref="^.list" class="btn btn-default"><i class="fa fa-arrow-left"></i></a>

<span ng-show="!item.id">Add a new item</span>
<span ng-show="item.id">Edit item</span>
<span ng-show="!page.id">Add a new page</span>
<span ng-show="page.id">Edit page</span>

</h4>


<div class="row">
<div class="col-md-4">
<div class="alert alert-danger" ng-if="addError">Could not add item!</div>
<formly-form result="item" fields="formFields" options="formOptions" ng-submit="onSubmit()"></formly-form>
<div class="alert alert-danger" ng-if="addError">Could not add page!</div>
<formly-form result="page" fields="formFields" options="formOptions" ng-submit="onSubmit()"></formly-form>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@


<div class='list-group'>
<div ng-repeat="item in items" class="list-group-item">
<div ng-repeat="page in pages" class="list-group-item">

<span class="pull-right btn-group" style="margin-top: 7px;">
<a href="" class="btn btn-sm btn-default" ui-sref="^.edit({id: item.id})">
<a href="" class="btn btn-sm btn-default" ui-sref="^.edit({id: page.id})">
<i class="fa fa-pencil"></i>
</a>
<a href="" class="btn btn-sm btn-default" ng-click="delete({id: item.id})">
<a href="" class="btn btn-sm btn-default" ng-click="delete({id: page.id})">
<i class="fa fa-trash-o"></i>
</a>
</span>

<h4 class="list-group-item-heading">
<a href="" ui-sref="^.view({id: item.id})">{{item.name}}</a>
<a href="" ui-sref="^.view({id: page.id})">{{page.name}}</a>
</h4>
<p class="list-group-item-text">{{item.description}}</p>

<p class="list-group-item-text">{{page.slug}}</p>
</div>

<div ng-show="!items.length" class="list-group-item">
<div ng-show="!pages.length" class="list-group-item">
<h4 class="list-group-item-heading">
There are no items
There are no pages
</h4>
<p class="list-group-item-text">Click <a href="" ui-sref="^.add">here</a> to add one!</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

<h2 class="page-header">
Items
<small>Manage your items here!</small>
Pages
<small>Manage your pages here!</small>
<a ui-sref=".add" class="btn btn-default pull-right">Add</a>
</h2>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

<h4>
<a href="" ui-sref="^.list" class="btn btn-default"><i class="fa fa-arrow-left"></i></a>
{{item.name}}
{{page.name}}

<span class="pull-right btn-group" style="margin-top: 7px;">
<a href="" class="btn btn-sm btn-default" ui-sref="^.edit({id: item.id})">
<a href="" class="btn btn-sm btn-default" ui-sref="^.edit({id: page.id})">
<i class="fa fa-pencil"></i>
</a>
<a href="" class="btn btn-sm btn-default" ng-click="delete({id: item.id})">
<a href="" class="btn btn-sm btn-default" ng-click="delete({id: page.id})">
<i class="fa fa-trash-o"></i>
</a>
</span>

</h4>
<hr>
<pre>{{item | json}}</pre>
<pre>{{page | json}}</pre>
13 changes: 10 additions & 3 deletions common/models/item.json → common/models/page.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
{
"name": "item",
"plural": "items",
"name": "Page",
"plural": "pages",
"base": "PersistedModel",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string",
"required": true
},
"slug": {
"type": "string"
},
"content": {
"type": "string"
},
"description": {
"extended": {
"type": "string"
}
},
Expand Down
2 changes: 1 addition & 1 deletion server/model-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dataSource": "db",
"public": false
},
"item": {
"Page": {
"dataSource": "db",
"public": true
},
Expand Down

0 comments on commit 88254ce

Please sign in to comment.