Skip to content

Improve error display #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ declare module fng {
formName: string;
alertTitle: any;
errorMessage: any;
errorHideTimer: number;
save: any;
newRecord: boolean;
initialiseNewRecord?: any;
Expand Down Expand Up @@ -334,7 +335,8 @@ declare module fng {
generateNewUrl: any;
scrollTheList: any;
getListData: any;
dismissError: any;
dismissError: () => void;
stickError: () => void;
handleHttpError: (response: any) => void;
dropConversionWatcher: () => void;
}
Expand Down
44 changes: 24 additions & 20 deletions src/client/js/controllers/nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,32 +98,36 @@ module fng.controllers {
});

$scope.doClick = function (index, event) {
var option = angular.element(event.target);
var item = $scope.items[index];
const option = angular.element(event.target);
const item = $scope.items[index];
if (item.divider || option.parent().hasClass('disabled')) {
event.preventDefault();
} else if (item.broadcast) {
$scope.$broadcast(item.broadcast);
} else {
// Performance optimization: http://jsperf.com/apply-vs-call-vs-invoke
var args = item.args || [],
fn = item.fn;
switch (args.length) {
case 0:
fn();
break;
case 1:
fn(args[0]);
break;
case 2:
fn(args[0], args[1]);
break;
case 3:
fn(args[0], args[1], args[2]);
break;
case 4:
fn(args[0], args[1], args[2], args[3]);
break;
const args = item.args || [];
const fn = item.fn;
if (typeof fn === "function") {
switch (args.length) {
case 0:
fn();
break;
case 1:
fn(args[0]);
break;
case 2:
fn(args[0], args[1]);
break;
case 3:
fn(args[0], args[1], args[2]);
break;
case 4:
fn(args[0], args[1], args[2], args[3]);
break;
}
} else if (fn) {
throw new Error("Incorrect menu setup")
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/client/js/directives/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module fng.directives {
' </a>' +
' <ul class="uib-dropdown-menu dropdown-menu">' +
' <li ng-repeat="choice in items" ng-hide="isHidden($index)" ng-class="dropdownClass($index)">' +
' <a ng-show="choice.text" class="dropdown-option" ng-href="{{choice.url}}" ng-click="doClick($index, $event)">' +
' <a ng-show="choice.text" class="dropdown-option" ng-href="{{choice.url || choice.urlFunc()}}" ng-click="doClick($index, $event)">' +
' {{choice.text}}' +
' </a>' +
' </li>' +
Expand Down
10 changes: 2 additions & 8 deletions src/client/js/directives/error-display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
module fng.directives {

/*@ngInject*/
export function errorDisplay() : angular.IDirective {
export function errorDisplay(cssFrameworkService) : angular.IDirective {
return {
restrict: 'E',
template: '<div id="display-error" ng-show="errorMessage" ng-class="css(\'rowFluid\')">' +
' <div class="alert alert-error col-lg-offset-3 offset3 col-lg-6 col-xs-12 span6 alert-warning alert-dismissable">' +
' <button type="button" class="close" ng-click="dismissError()">×</button>' +
' <h4>{{alertTitle}}</h4>' +
' <div ng-bind-html="errorMessage"></div>' +
' </div>' +
'</div>'
templateUrl: 'error-display-' + cssFrameworkService.framework() + '.html'
};
}
}
10 changes: 9 additions & 1 deletion src/client/js/services/record-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -905,13 +905,21 @@ module fng.services {
$scope.errorMessage = error;
}
}
$scope.errorHideTimer = window.setTimeout(function() {
$scope.dismissError();
$scope.$digest();
}, 2000 + (1000 * ($scope.alertTitle + $scope.errorMessage).length / 40));
};

$scope.dismissError = function () {
$scope.dismissError = function(fade = false) {
delete $scope.errorMessage;
delete $scope.alertTitle;
};

$scope.stickError = function() {
clearTimeout($scope.errorHideTimer);
};

$scope.prepareForSave = function(cb: (error: string, dataToSave?: any) => void): void {
//Convert the lookup values into ids
let dataToSave = recordHandlerInstance.convertToMongoModel($scope.formSchema, angular.copy($scope.record), 0, $scope);
Expand Down
13 changes: 13 additions & 0 deletions src/client/less/forms-angular-bs-common.less
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,16 @@ button#saveButton[disabled]:hover + #why-disabled.showwhy {
font-weight: normal;
top: 22px;
}

#display-error {
transition: opacity .5s ease-in-out;
position: fixed;
top: 60px;
width: 100%;
}

input[type="checkbox"].ng-invalid::after {
content: "Invalid";
color: rgba(255, 0, 0, 0.6);
padding-left: 1em;
}
2 changes: 1 addition & 1 deletion src/client/template/base-analysis.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div ng-controller="AnalysisCtrl">
<error-display></error-display>
<div class="container-fluid page-header report-header">
<div ng-class="css('rowFluid')">
<div class="header-lhs col-xs-7 span7">
Expand All @@ -10,7 +11,6 @@ <h1>{{ reportSchema.title }}</h1>
</div>
</div>
<div class="container-fluid page-body report-body">
<error-display></error-display>
<div class="row-fluid">
<div class="gridStyle" ui-grid="gridOptions" ui-grid-selection></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/client/template/base-edit.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div ng-controller="BaseCtrl">
<error-display></error-display>
<div ng-class="css('rowFluid')" class="page-header edit-header">
<div class="header-lhs col-sm-8 span8">
<h4>{{modelNameDisplay}} :
Expand All @@ -10,7 +11,6 @@ <h4>{{modelNameDisplay}} :
</div>
</div>
<div class="container-fluid page-body edit-body">
<error-display></error-display>
<form-input name="baseForm" schema="baseSchema()" formstyle="compact"></form-input>
</div>
<!--{{ formSchema | json }}-->
Expand Down
2 changes: 1 addition & 1 deletion src/client/template/base-list-view.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div ng-controller="BaseCtrl">
<error-display></error-display>
<div ng-class="css('rowFluid')" class="page-header list-header">
<div class="header-lhs col-sm-8 span8">
<h1>{{modelNameDisplay}}</h1>
</div>
</div>
<div class="page-body list-body">
<error-display></error-display>
<div ng-class="css('rowFluid')" infinite-scroll="scrollTheList()">
<a ng-repeat="record in recordList" ng-href="{{generateViewUrl(record)}}">
<div class="list-item">
Expand Down
2 changes: 1 addition & 1 deletion src/client/template/base-list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div ng-controller="BaseCtrl">
<error-display></error-display>
<div ng-class="css('rowFluid')" class="page-header list-header">
<div class="header-lhs col-sm-8 span8">
<h1>{{modelNameDisplay}}</h1>
Expand All @@ -8,7 +9,6 @@ <h1>{{modelNameDisplay}}</h1>
</div>
</div>
<div class="page-body list-body">
<error-display></error-display>
<div ng-class="css('rowFluid')" infinite-scroll="scrollTheList()">
<a ng-repeat="record in recordList" ng-href="{{generateEditUrl(record)}}">
<div class="list-item">
Expand Down
2 changes: 1 addition & 1 deletion src/client/template/base-view.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div ng-controller="BaseCtrl">
<error-display></error-display>
<div ng-class="css('rowFluid')" class="page-header edit-header">
<div class="header-lhs col-sm-8 span8">
<h4>{{modelNameDisplay}} :
Expand All @@ -7,7 +8,6 @@ <h4>{{modelNameDisplay}} :
</div>
</div>
<div class="container-fluid page-body edit-body">
<error-display></error-display>
<form-input name="baseForm" schema="baseSchema()" formstyle="compact" viewform="true"></form-input>
</div>
</div>
8 changes: 8 additions & 0 deletions src/client/template/error-display-bs2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div id="display-error" ng-style="{opacity : errorMessage ? '1' : '0', 'z-index' : errorMessage ? '130' : '0'}" class="row-fluid">
<div class="alert alert-error offset1 span10 alert-warning ">
<button type="button" class="close" ng-click="dismissError()"><i class="icon-remove"></i></button>
<button type="button" class="close" ng-click="stickError()"><i class="icon-stop"></i></button>
<h4>{{alertTitle}}</h4>
<div ng-bind-html="errorMessage"></div>
</div>
</div>
8 changes: 8 additions & 0 deletions src/client/template/error-display-bs3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div id="display-error" ng-style="{opacity : errorMessage ? '1' : '0', 'z-index' : errorMessage ? '130' : '0'}" class="row">
<div class="alert col-md-offset-1 col-md-10 alert-warning ">
<button type="button" class="close" ng-click="dismissError()"><i class="glyphicon glyphicon-remove"></i></button>
<button type="button" class="close" ng-click="stickError()"><i class="glyphicon glyphicon-pushpin"></i></button>
<h4>{{alertTitle}}</h4>
<div ng-bind-html="errorMessage"></div>
</div>
</div>
1 change: 1 addition & 0 deletions website/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ formsAngular.config(['$locationProvider', 'cssFrameworkServiceProvider', 'routin
/**
* The rest of this file is all about testing different frameworks and will almost certainly be of no interest to
* anyone not working on forms-angular itself
* to specify the framework for testing open a new browser tab and enter localhost:9000/#/bs3 (or whichever framework)
**/

websiteApp.css = {
Expand Down
22 changes: 11 additions & 11 deletions website/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "website",
"author": "Mark Chapman <support@forms-angular.org>",
"version": "0.12.0-beta.43",
"version": "0.12.0-beta.45",
"description": "The demonstration website for the forms-angular library",
"repository": {
"type": "git",
Expand All @@ -27,16 +27,16 @@
"compression": "1.7.4",
"errorhandler": "1.5.1",
"express": "4.17.1",
"fng-audit": "0.12.0-beta.43",
"fng-bootstrap-date": "0.12.0-beta.43",
"fng-bootstrap-datetime": "0.12.0-beta.43",
"fng-ckeditor": "0.12.0-beta.43",
"fng-colour-picker": "^0.12.0-beta.43",
"fng-jq-upload": "0.12.0-beta.43",
"fng-reports": "^0.12.0-beta.43",
"fng-ui-date": "0.12.0-beta.43",
"fng-ui-select": "0.12.0-beta.43",
"forms-angular": "^0.12.0-beta.43",
"fng-audit": "0.12.0-beta.45",
"fng-bootstrap-date": "0.12.0-beta.45",
"fng-bootstrap-datetime": "0.12.0-beta.45",
"fng-ckeditor": "0.12.0-beta.45",
"fng-colour-picker": "^0.12.0-beta.45",
"fng-jq-upload": "0.12.0-beta.45",
"fng-reports": "^0.12.0-beta.45",
"fng-ui-date": "0.12.0-beta.45",
"fng-ui-select": "0.12.0-beta.45",
"forms-angular": "^0.12.0-beta.45",
"jspdf-autotable": "^3.2.4",
"lodash": "^4.17.15",
"method-override": "3.0.0",
Expand Down