This repository has been archived by the owner on Jul 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
151 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
|
||
}; | ||
|
||
|
||
}); |
8 changes: 4 additions & 4 deletions
8
client/app/views/items/form.html → client/app/views/pages/form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
17 changes: 7 additions & 10 deletions
17
client/app/views/items/list.html → client/app/views/pages/list.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
client/app/views/items/main.html → client/app/views/pages/main.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
client/app/views/items/view.html → client/app/views/pages/view.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
"dataSource": "db", | ||
"public": false | ||
}, | ||
"item": { | ||
"Page": { | ||
"dataSource": "db", | ||
"public": true | ||
}, | ||
|