This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from jpkrohling/HAWKULAR-468-UserSettings
HAWKULAR-468 - Implemented User Settings
- Loading branch information
Showing
9 changed files
with
233 additions
and
2 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
console/src/main/scripts/plugins/accounts/html/user-settings.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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<div class="hk-user-settings" ng-controller="HawkularAccounts.UserSettingsController as controller"> | ||
|
||
<div class="text-center hk-spinner-container-alone" ng-show="controller.loading"> | ||
<div class="spinner spinner-lg"></div> | ||
<p class="hk-spinner-legend-below">Loading...</p> | ||
</div> | ||
|
||
<h1 class="text-center" ng-show="!controller.loading">User Settings</h1> | ||
<form name="form" class="form-horizontal" ng-show="!controller.loading" novalidate> | ||
<fieldset> | ||
<legend>Alert Notifications</legend> | ||
<p>Receive alert notifications on the following email. | ||
<div class="form-group" ng-class="{'has-error': form.email.$error.emails}"> | ||
<label class="col-sm-3 control-label" for="email">Email | ||
<a class="hk-btn-icon" | ||
tabindex="0" | ||
role="button" | ||
tooltip-trigger | ||
tooltip-placement="top" | ||
tooltip="For multiple emails, separate by comma."> | ||
<i class="fa fa-info-circle"></i> | ||
</a> | ||
</label> | ||
<div class="col-sm-6"> | ||
<input | ||
type="text" | ||
name="email" | ||
id="email" | ||
class="form-control" | ||
hawkular-emails | ||
ng-model="controller.settings['hawkular.settings.emails']"> | ||
<span class="help-block" ng-show="form.email.$error.emails"> | ||
Please enter valid email addresses. | ||
</span> | ||
|
||
<span class="help-block" ng-show="!form.email.$error.emails"> | ||
Emails are valid. | ||
</span> | ||
</div> | ||
</div> | ||
</fieldset> | ||
<div class="form-actions text-right" ng-show="!controller.loading"> | ||
<button type="button" class="btn btn-default">Cancel</button> | ||
<button type="button" class="btn btn-primary" ng-disabled="!form.$valid" ng-click="controller.save()"> | ||
Save | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
<!-- /col --> |
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
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,67 @@ | ||
/// | ||
/// Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
/// and other contributors as indicated by the @author tags. | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// http://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
/// | ||
|
||
/// <reference path='accountsPlugin.ts'/> | ||
|
||
module HawkularAccounts { | ||
export class UserSettingsController { | ||
public static $inject = ['$log', | ||
'HawkularAccount', | ||
'NotificationsService' | ||
]; | ||
|
||
// backend data related to this controller | ||
public settings:IUserSettings; | ||
|
||
// state control, for easier UI consumption | ||
public loading:boolean; | ||
|
||
constructor(private $log:ng.ILogService, | ||
private HawkularAccount:any, | ||
private NotificationsService:INotificationsService) { | ||
|
||
this.loadData(); | ||
} | ||
public loadData():void { | ||
this.loading = true; | ||
this.loadSettings(); | ||
} | ||
|
||
public loadSettings():void { | ||
this.settings = this.HawkularAccount.Settings.get({}, | ||
(settings:IUserSettings) => { | ||
this.loading = false; | ||
}, | ||
(error:IErrorPayload) => { | ||
this.NotificationsService.warning('User settings could not be loaded.'); | ||
this.$log.warn(`Error while loading the organization: ${error.data.message}`); | ||
this.loading = false; | ||
} | ||
); | ||
} | ||
|
||
public save():void { | ||
this.settings.$update({}, (settings:IUserSettings) => { | ||
this.NotificationsService.success('User settings successfully updated.'); | ||
}, (error:IErrorPayload) => { | ||
this.NotificationsService.error('User settings could not be updated.'); | ||
}); | ||
} | ||
} | ||
|
||
_module.controller('HawkularAccounts.UserSettingsController', UserSettingsController); | ||
} |
48 changes: 48 additions & 0 deletions
48
console/src/main/scripts/plugins/directives/emails/ts/emailsDirective.ts
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,48 @@ | ||
/// | ||
/// Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
/// and other contributors as indicated by the @author tags. | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// http://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
/// | ||
|
||
/// <reference path='emailsPlugin.ts'/> | ||
module Emails { | ||
export class EmailsDirective { | ||
public require = 'ngModel'; | ||
|
||
public link(scope, elm, attrs, ctrl):void { | ||
ctrl.$validators.emails = (modelValue, viewValue):boolean => { | ||
if (ctrl.$isEmpty(modelValue)) { | ||
// consider empty models to be valid | ||
return true; | ||
} | ||
|
||
let atLeastOneInvalid = true; // until proven otherwise... | ||
viewValue | ||
.split(/[,\s]/) | ||
.filter((entry:string) => { | ||
return entry && entry.length > 0; | ||
}) | ||
.forEach((email:string) => { | ||
const re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; | ||
let valid = re.test(email); | ||
if (!valid) { | ||
atLeastOneInvalid = false; | ||
} | ||
}); | ||
|
||
return atLeastOneInvalid; | ||
}; | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
console/src/main/scripts/plugins/directives/emails/ts/emailsGlobals.ts
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,22 @@ | ||
/// | ||
/// Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
/// and other contributors as indicated by the @author tags. | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// http://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
/// | ||
|
||
/// <reference path='../../includes.ts'/> | ||
module Emails { | ||
export var pluginName = 'emails'; | ||
export let _module = angular.module(pluginName, ['ui.bootstrap']); | ||
} |
27 changes: 27 additions & 0 deletions
27
console/src/main/scripts/plugins/directives/emails/ts/emailsPlugin.ts
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,27 @@ | ||
/// | ||
/// Copyright 2015 Red Hat, Inc. and/or its affiliates | ||
/// and other contributors as indicated by the @author tags. | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// http://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
/// | ||
|
||
/// <reference path="../../includes.ts"/> | ||
/// <reference path="emailsGlobals.ts"/> | ||
/// <reference path="emailsDirective.ts"/> | ||
module Emails { | ||
_module.directive('hawkularEmails', () => { | ||
return new Emails.EmailsDirective(); | ||
}); | ||
|
||
hawtioPluginLoader.addModule(pluginName); | ||
} |
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