Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #538 from jpkrohling/HAWKULAR-468-UserSettings
Browse files Browse the repository at this point in the history
HAWKULAR-468 - Implemented User Settings
  • Loading branch information
mtho11 committed Oct 8, 2015
2 parents bef44ab + 00364f8 commit 732c776
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 2 deletions.
50 changes: 50 additions & 0 deletions console/src/main/scripts/plugins/accounts/html/user-settings.html
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 -->
10 changes: 10 additions & 0 deletions console/src/main/scripts/plugins/accounts/ts/accountsGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ module HawkularAccounts {
failure?:(error:IErrorPayload) => void);
}

export interface IUserSettings {
id: string;
$update(options?:{},
success?:(success:IUserSettings) => void,
failure?:(error:IErrorPayload) => void);
$get(options?:{},
success?:(success:IUserSettings) => void,
failure?:(error:IErrorPayload) => void);
}

// specialized payloads, requests and responses
export interface IDataPayload {
message: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ module HawkularAccounts {

.when(
'/hawkular-ui/invitation/accept/:token',
{templateUrl: builder.join(HawkularAccounts.templatePath, 'organization-accept-invitation.html')});
{templateUrl: builder.join(HawkularAccounts.templatePath, 'organization-accept-invitation.html')})

.when(
'/hawkular-ui/settings',
{templateUrl: builder.join(HawkularAccounts.templatePath, 'user-settings.html')});
}]);

_module.run(['$rootScope', '$log', '$modal', '$document', 'userDetails',
Expand Down
67 changes: 67 additions & 0 deletions console/src/main/scripts/plugins/accounts/ts/settings.ts
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);
}
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;
};
}
}
}
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']);
}
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);
}
3 changes: 3 additions & 0 deletions console/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
<li>
<a id="organizationsOption" href="/hawkular-ui/organizations">Manage Organizations</a>
</li>
<li>
<a id="userSettingsOption" href="/hawkular-ui/settings">User Settings</a>
</li>
<li class="divider"></li>
<li>
<a id="logout" href="#" ng-click="userDetails.logout()">Log Out</a>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<version.com.google.guava>16.0.1</version.com.google.guava>
<version.commons.io>2.4</version.commons.io>
<version.gnu.getopt>1.0.13</version.gnu.getopt>
<version.org.hawkular.accounts>1.0.16.Final-SRC-revision-3f499fed1a9fbc506ee6f72bd346a87e87621dc3</version.org.hawkular.accounts>
<version.org.hawkular.accounts>1.0.16.Final-SRC-revision-9ed58ca8de4e0e4cbbfdf35cf782bc2a522ae99f</version.org.hawkular.accounts>
<version.org.hawkular.agent>0.10.1.Final-SRC-revision-978a81e1a3f688e1505950d2c67d3c615c0b313d</version.org.hawkular.agent>
<version.org.hawkular.alerts>0.5.0.Final-SRC-revision-1386ca7dc771bc65c7c322e98246b445539bc017</version.org.hawkular.alerts>
<version.org.hawkular.bus>0.7.0.Final</version.org.hawkular.bus>
Expand Down

0 comments on commit 732c776

Please sign in to comment.