Skip to content

Commit c38be6c

Browse files
committed
Readonly working
1 parent 4cae1b1 commit c38be6c

File tree

6 files changed

+61
-16
lines changed

6 files changed

+61
-16
lines changed

src/client/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ declare module fng {
241241

242242
export interface IFormGenerator {
243243
generateEditUrl(obj, $scope:IFormScope): string;
244+
generateViewUrl(obj, $scope:IFormScope): string;
244245
generateNewUrl($scope: IFormScope): string;
245246
handleFieldType(formInstructions, mongooseType, mongooseOptions, $scope: IFormScope, ctrlState);
246247
handleSchema(description: string, source, destForm, destList, prefix, doRecursion: boolean, $scope: IFormScope, ctrlState);
@@ -329,6 +330,7 @@ declare module fng {
329330
skipCols: any;
330331
setPristine: any;
331332
generateEditUrl: any;
333+
generateViewUrl: any;
332334
generateNewUrl: any;
333335
scrollTheList: any;
334336
getListData: any;

src/client/js/services/fng-routes.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ module fng.services {
2828
{route: '/:model/:id/view/:tab', state: 'model::view::tab', templateUrl: 'base-view.html'},
2929
{route: '/:model/new', state: 'model::new', templateUrl: 'base-edit.html'},
3030
{route: '/:model', state: 'model::list', templateUrl: 'base-list.html'},
31+
{route: '/:model/viewonly', state: 'model::view', templateUrl: 'base-list-view.html'},
3132

3233
// Non default form (subset of fields etc)
3334
{route: '/:model/:form/:id/edit', state: 'model::form::edit', templateUrl: 'base-edit.html'},
3435
{route: '/:model/:form/:id/edit/:tab', state: 'model::form::edit::tab', templateUrl: 'base-edit.html'},
3536
{route: '/:model/:form/:id/view', state: 'model::form::view', templateUrl: 'base-view.html'},
3637
{route: '/:model/:form/:id/view/:tab', state: 'model::form::view::tab', templateUrl: 'base-view.html'},
3738
{route: '/:model/:form/new', state: 'model::form::new', templateUrl: 'base-edit.html'},
38-
{route: '/:model/:form', state: 'model::form::list', templateUrl: 'base-list.html'} // list page with edit links to non default form
39+
{route: '/:model/:form', state: 'model::form::list', templateUrl: 'base-list.html'}, // list page with edit links to non default form
40+
{route: '/:model/:form/:viewonly', state: 'model::form::list::view', templateUrl: 'base-list-view.html'} // list page with edit links to non default form
3941
];
4042

4143
var _routeProvider, _stateProvider;
@@ -94,6 +96,9 @@ module fng.services {
9496
case 'edit' :
9597
urlStr = modelString + formString + '/' + id + '/edit' + tabString;
9698
break;
99+
case 'view' :
100+
urlStr = modelString + formString + '/' + id + '/view' + tabString;
101+
break;
97102
case 'read' :
98103
urlStr = modelString + formString + '/' + id + '/read' + tabString;
99104
break;
@@ -180,8 +185,9 @@ module fng.services {
180185
lastObject.modelName = locationSplit[1];
181186
let lastParts = [locationSplit[locationParts - 1], locationSplit[locationParts - 2]];
182187
let newPos = lastParts.indexOf('new');
188+
let viewonlyPos = lastParts.indexOf('viewonly');
183189
let actionPos;
184-
if (newPos === -1) {
190+
if (newPos === -1 && viewonlyPos === -1) {
185191
actionPos = postActions.reduce((previousValue, currentValue) => {
186192
let pos = lastParts.indexOf(currentValue);
187193
return pos > -1 ? pos : previousValue
@@ -190,9 +196,11 @@ module fng.services {
190196
locationParts -= (2 + actionPos);
191197
lastObject.id = locationSplit[locationParts];
192198
}
193-
} else {
199+
} else if (newPos !== -1) {
194200
lastObject.newRecord = true;
195201
locationParts -= (1 + newPos);
202+
} else {
203+
locationParts -= (1 + viewonlyPos);
196204
}
197205
if (actionPos === 1 || newPos === 1) {
198206
lastObject.tab = lastParts[0];

src/client/js/services/form-generator.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ module fng.services {
358358
generateEditUrl: function generateEditUrl(obj, $scope:fng.IFormScope):string {
359359
return routingService.buildUrl($scope.modelName + '/' + ($scope.formName ? $scope.formName + '/' : '') + obj._id + '/edit');
360360
},
361+
generateViewUrl: function generateViewUrl(obj, $scope:fng.IFormScope):string {
362+
return routingService.buildUrl($scope.modelName + '/' + ($scope.formName ? $scope.formName + '/' : '') + obj._id + '/view');
363+
},
361364
generateNewUrl: function generateNewUrl($scope):string {
362365
return routingService.buildUrl($scope.modelName + '/' + ($scope.formName ? $scope.formName + '/' : '') + 'new');
363366
},
@@ -517,6 +520,10 @@ module fng.services {
517520
return formGeneratorInstance.generateEditUrl(obj, $scope);
518521
};
519522

523+
$scope.generateViewUrl = function (obj) {
524+
return formGeneratorInstance.generateViewUrl(obj, $scope);
525+
};
526+
520527
$scope.generateNewUrl = function () {
521528
return formGeneratorInstance.generateNewUrl($scope);
522529
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div ng-controller="BaseCtrl">
2+
<div ng-class="css('rowFluid')" class="page-header list-header">
3+
<div class="header-lhs col-sm-8 span8">
4+
<h1>{{modelNameDisplay}}</h1>
5+
</div>
6+
</div>
7+
<div class="page-body list-body">
8+
<error-display></error-display>
9+
<div ng-class="css('rowFluid')" infinite-scroll="scrollTheList()">
10+
<a ng-repeat="record in recordList" ng-href="{{generateViewUrl(record)}}">
11+
<div class="list-item">
12+
<div ng-class="css('span',12/listSchema.length)" ng-repeat="field in listSchema">{{getListData(record, field.name)}} </div>
13+
</div>
14+
</a>
15+
</div>
16+
</div>
17+
</div>

website/app/partials/forms.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,31 @@ <h1>Forms</h1>
3333

3434
<ul>
3535
<li><strong>/#/:model</strong> which lists the documents in the collection, with links to the form for editing them</li>
36+
<li><strong>/#/:model/viewonly</strong> which lists the documents in the collection, with links to a readonly form for viewing them</li>
3637
<li><strong>/#/:model/new</strong> which enables the user to create a new document using the default form for the collection. It is also possible to override the
3738
default values for new records passing the desired record as follows: <code>/#/:model/new?r={"field1":"value1","field2":"value2"}</code></li>
3839
<li><strong>/#/:model/:id/edit</strong> which enables the user to edit a document</li>
3940
<li><strong>/#/:model/:id/edit/:tab</strong> which enables the user to edit a document, opening a tabbed form at a specified tab</li>
41+
<li><strong>/#/:model/:id/view</strong> which enables the user to view a document in a read-only form</li>
42+
<li><strong>/#/:model/:id/view/:tab</strong> which enables the user to view a document in a read-only form, opening a tabbed form at a specified tab</li>
4043
</ul>
44+
<p>
45+
Each view created from the <a href="/#/schemas#custom">custom form schemas</a> will also have routes
46+
generated to them which only differ in that they have the schema name added as an additional parameter after the model:
47+
</p>
48+
49+
<ul>
50+
<li><strong>/#/:model/:formschema</strong> which lists the documents in the collection, with links to the form for editing them
51+
(example <a ng-href="{{buildUrl('b_enhanced_schema/justnameandpostcode/')}}">here</a>).</li>
52+
<li><strong>/#/:model/:formschema/viewonly</strong> which lists the documents in the collection, with links to the form for editing them</li>
53+
</ul>
54+
<p>etc</p>
55+
<!-- <li><strong>/#/:model/:formschema/new</strong> which enables the user to create a new document using the default form for the collection. It is also possible to override the-->
56+
<!-- default values for new records passing the desired record as follows: <code>/#/:model/new?r={"field1":"value1","field2":"value2"}</code></li>-->
57+
<!-- <li><strong>/#/:model/:formschema/:id/edit</strong> which enables the user to edit a document</li>-->
58+
<!-- <li><strong>/#/:model/:formschema/:id/edit/:tab</strong> which enables the user to edit a document, opening a tabbed form at a specified tab</li>-->
59+
<!-- <li><strong>/#/:model/:formschema/:id/view</strong> which enables the user to view a document in a read-only form</li>-->
60+
<!-- <li><strong>/#/:model/:formschema/:id/view/:tab</strong> which enables the user to view a document in a read-only form, opening a tabbed form at a specified tab</li>-->
4161

4262
<p>These routes are set up by making a call such as:<pre><code>myDemoApp.config(['formRoutesProvider', function (formRoutes) {
4363
formRoutes.start({
@@ -335,7 +355,7 @@ <h5>Client side data events</h5>
335355
</p>
336356
<h5 id="#button-hooks">Controlling CRUD button enabled state</h5>
337357
<p>There are hooks to override the default CRUD button enabled state behaviour. There is a trivial example which uses this capability to create
338-
a read-only view can be found in the controller <a href="/scripts/controllers/b-enhanced-schema-readonly.js">here</a>. The functions are
358+
a read-only view can be found in the controller <a href="/scripts/controllers/b-enhanced-schema-readonly.js">here</a> (which is much the same as using the /view routes family). The functions are
339359
passed three parameters: <strong>record</strong>, <strong>originalRecord</strong> and <strong>form</strong> and return a boolean, except in the case of
340360
isSaveDisabled, which can return a boolean or a string explaining what the problem is. This string is displayed when the user hovers over
341361
the disabled Save button.

website/app/partials/schemas.html

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,19 +331,10 @@ <h3>Custom Schemas</h3>
331331

332332
<p>It is easy to create custom form schemas which are a subset of the whole schema by specifying the
333333
fields to include and any options. See the static in <a href="/models/b_enhanced_schema.js">this example</a>.
334-
The custom form schemas are invoked as follows:
334+
These schemas are automatically used to generate custom views and routes to them (see <a href="/#/forms#routes">here</a>).
335335
</p>
336-
<ul>
337-
<li><strong>/#/:model/:formschema</strong> (<a ng-href="{{buildUrl('b_enhanced_schema/justnameandpostcode/')}}">example
338-
here</a>)
339-
</li>
340-
<li><strong>/#/:model/:formschema/new</strong> (<a ng-href="{{buildUrl('b_enhanced_schema/justnameandpostcode/new')}}">example
341-
here</a>)
342-
</li>
343-
<li><strong>/#/:model/:formschema/:id/edit</strong></li>
344-
</ul>
345-
<p>It is also possible to show a subset of fields in a sub-schema, which can be seen (<a ng-href="{{buildUrl('f_nested_schema/ResultsOnly/new')}}">here</a>
346-
if you add a new exam.</p>
336+
<p>It is also possible to show a subset of fields in a sub-schema (which can be seen <a ng-href="{{buildUrl('f_nested_schema/ResultsOnly/new')}}">here</a>
337+
if you add a new exam).</p>
347338

348339
<h4>Subkeys</h4>
349340
<p>Custom schemas are a good way to allow access to only part of a document, for instance if a customer record contained operational

0 commit comments

Comments
 (0)