Skip to content

Commit 798d077

Browse files
committed
add preview view
1 parent 665094d commit 798d077

13 files changed

+127
-11
lines changed

crud-gen.js

+9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ module.exports = {
3535
{
3636
local: require.resolve('./edit')
3737
});
38+
generator.composeWith('aaal:view', {
39+
args: [model.name],
40+
options: {
41+
model: model
42+
}
43+
},
44+
{
45+
local: require.resolve('./view')
46+
});
3847

3948
},
4049

default-settings.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
testPassOnDefault: true,
66
stylePrefix: '_',
77
editorCommand: 'idea',
8+
uiRouter: true,
89
baseState: 'private.',
910
moduleName: 'aaal',
1011
pathOutputStyle: 'dasherize',
@@ -41,19 +42,22 @@ module.exports = {
4142
stateSuffix: 'List',
4243
subRoute: 'list',
4344
suffix: '-list-c',
44-
nameSuffix: 'ListCtrl'
45+
nameSuffix: 'ListCtrl',
46+
createDirectory: true
4547
},
4648
edit: {
4749
stateSuffix: 'Edit',
4850
subRoute: 'edit',
4951
suffix: '-edit-c',
50-
nameSuffix: 'EditCtrl'
52+
nameSuffix: 'EditCtrl',
53+
createDirectory: true
5154
},
52-
preview: {
55+
view: {
5356
stateSuffix: 'View',
5457
subRoute: 'view',
5558
suffix: '-view-c',
56-
nameSuffix: 'ViewCtrl'
59+
nameSuffix: 'ViewCtrl',
60+
createDirectory: true
5761
}
5862
}
5963
};

edit/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var chalk = require('chalk');
88
module.exports = ScriptBase.extend({
99
initializing: function() {
1010
this.templateName = 'edit';
11+
1112
// needs to be called manually
1213
this.init();
1314
},
@@ -18,7 +19,7 @@ module.exports = ScriptBase.extend({
1819

1920
this.log.writeln(chalk.yellow('injecting state into ' + this.routesFile));
2021

21-
var routeUrl = '/' + this.formatNamePath(this.name) + '/' + this.formatNamePath(this.subGenCfg.subRoute);
22+
var routeUrl = '/' + this.formatNamePath(this.name) + '/' + this.formatNamePath(this.subGenCfg.subRoute) + '/:id';
2223
var tplUrl = this.tplUrl;
2324
var ctrl = this.classedName + (this.subGenCfg.nameSuffix || '');
2425

sub-generator-base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = yeoman.generators.NamedBase.extend({
4848
this.modelOptions = helper.simpleObjectToString(this.options.model, ' ');
4949
this.overviewStateFull = this.baseState + this.name + this.subGenerators.overview.stateSuffix;
5050
this.editStateFull = this.baseState + this.name + this.subGenerators.edit.stateSuffix;
51-
this.previewStateFull = this.baseState + this.name + this.subGenerators.preview.stateSuffix;
51+
this.previewStateFull = this.baseState + this.name + this.subGenerators.view.stateSuffix;
5252

5353

5454
// instead use target folder to set the path

templates/app/_edit.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.page-<%= sluggedName %> {
1+
.page-<%= sluggedName %>-edit {
22

33
}

templates/app/_overview.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.page-<%= sluggedName %> {
1+
.page-<%= sluggedName %>-overview {
22

33
}

templates/app/_view.scss

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.page-<%= sluggedName %>-view {
2+
3+
}

templates/app/edit.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="page-<%=dashedName %>">
2-
<p>This is the <%= classedName %> view</p>
2+
<p>This is the <%= classedName edit view</p>
33
</div>

templates/app/overview.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
<i class="glyphicon glyphicon-remove-circle"></i>
4444
</button>
4545
<button type="button"
46-
ui-sref="<%=editStateFull%>(row.id)"
46+
ui-sref="<%=editStateFull%>({id:row.id})"
4747
class="btn btn-sm btn-info">
4848
<i class="glyphicon glyphicon-edit"></i>
4949
</button>
5050
<button type="button"
51-
ui-sref="<%=previewStateFull%>(row.id)"
51+
ui-sref="<%=previewStateFull%>({id:row.id})"
5252
class="btn btn-sm btn-default">
5353
<i class="glyphicon glyphicon-play-circle"></i>
5454
</button>

templates/app/view.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div class="page-<%=dashedName %>">
2+
<div>
3+
<button type="button"
4+
ui-sref="<%=overviewStateFull%>"
5+
class="btn btn-sm btn-default">
6+
<i class="glyphicon glyphicon-backward">
7+
</i> Back to overview
8+
</button>
9+
<button type="button"
10+
ui-sref="<%=editStateFull%>({id:model.id})"
11+
class="btn btn-sm btn-info">
12+
<i class="glyphicon glyphicon-edit">
13+
</i> Edit
14+
</button>
15+
</div>
16+
17+
<h2>{{ model.id }} {{ modelName || model.title }} </h2>
18+
<pre class="code">{{ model|json }}</pre>
19+
</div>

templates/app/view.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @ngdoc function
3+
* @name <%= moduleName %>.controller:<%= classedName %>Ctrl
4+
* @description
5+
* # <%= classedName %>Ctrl
6+
* Controller of the <%= moduleName %>
7+
*/
8+
angular.module('<%= moduleName %>')
9+
//.controller('<%= classedName %><%= nameSuffix %>', function myFunc($scope, $state, <%= modelServiceName %>) {
10+
// 'use strict';
11+
//
12+
// var ModelService = <%= modelServiceName %>;
13+
14+
.controller('<%= classedName %><%= nameSuffix %>', function myFunc($scope, $state, TestModel) {
15+
'use strict';
16+
17+
var ModelService = TestModel;
18+
19+
if ($state.params.id) {
20+
$scope.model = ModelService.findById({id: $state.params.id});
21+
}
22+
});

templates/app/view.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
describe('Controller: <%=classedName%><%=nameSuffix%>', function() {
4+
5+
// load the controller's module
6+
beforeEach(module('<%=moduleName%>'));
7+
8+
//var <%=classedName%><%=nameSuffix%>;
9+
var scope;
10+
11+
// Initialize the controller and a mock scope
12+
beforeEach(inject(function($controller, $rootScope) {
13+
scope = $rootScope.$new();
14+
//<%=classedName%><%=nameSuffix%> = $controller('<%=classedName%><%=nameSuffix%>', {
15+
// $scope: scope
16+
// place mocked dependencies here
17+
//});
18+
}));
19+
20+
it('should ...', function() {
21+
//expect(true).toBe(<%=testPassOnDefault%>);
22+
});
23+
});

view/index.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
var ScriptBase = require('../sub-generator-base.js');
3+
var helper = require('../helper.js');
4+
var path = require('path');
5+
var fs = require('fs');
6+
var chalk = require('chalk');
7+
8+
module.exports = ScriptBase.extend({
9+
initializing: function() {
10+
this.templateName = 'view';
11+
12+
// needs to be called manually
13+
this.init();
14+
},
15+
install: function() {
16+
// SOMEWHAT HACKY, but not possible otherwise to run
17+
// after file creation due to how the run queue works
18+
// @see http://yeoman.io/authoring/running-context.html
19+
20+
this.log.writeln(chalk.yellow('injecting state into ' + this.routesFile));
21+
22+
var routeUrl = '/' + this.formatNamePath(this.name) + '/' + this.formatNamePath(this.subGenCfg.subRoute) + '/:id';
23+
var tplUrl = this.tplUrl;
24+
var ctrl = this.classedName + (this.subGenCfg.nameSuffix || '');
25+
26+
helper.injectRoute(
27+
this.routesFile,
28+
this.stateName,
29+
routeUrl,
30+
tplUrl,
31+
ctrl,
32+
this
33+
);
34+
}
35+
});

0 commit comments

Comments
 (0)