alert and pagination
diff --git a/views/ngXosLib/.gitignore b/views/ngXosLib/.gitignore
index 34bf3a1..5df6f2d 100644
--- a/views/ngXosLib/.gitignore
+++ b/views/ngXosLib/.gitignore
@@ -1,4 +1,5 @@
node_modules
bower_components
docs
-xosHelpers/.tmp
\ No newline at end of file
+xosHelpers/.tmp
+xos
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/spec/ui/alert.test.js b/views/ngXosLib/xosHelpers/spec/ui/alert.test.js
new file mode 100644
index 0000000..c67d03a
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/spec/ui/alert.test.js
@@ -0,0 +1,131 @@
+/**
+ * © OpenCORD
+ *
+ * Created by teone on 4/15/16.
+ */
+
+(function () {
+ 'use strict';
+
+ describe('The xos.helper module', function(){
+ describe('The xos-alert component', () => {
+
+ let element, scope, isolatedScope;
+
+ let message = 'Test Error Message';
+
+ beforeEach(module('xos.helpers'));
+
+ it('should throw an error if no config is specified', inject(($compile, $rootScope) => {
+ function errorFunctionWrapper(){
+ $compile(angular.element('<xos-alert></xos-alert>'))($rootScope);
+ $rootScope.$digest();
+ }
+ expect(errorFunctionWrapper).toThrow(new Error('[xosAlert] Please provide a configuration via the "config" attribute'));
+ }));
+
+ describe('when correctly configured', () => {
+ beforeEach(inject(($compile, $rootScope) => {
+
+ scope = $rootScope.$new();
+
+ scope.config = {
+ type: 'danger',
+ closeBtn: true
+ };
+
+ element = angular.element(`<xos-alert config="config">${message}</xos-alert>`);
+ $compile(element)(scope);
+ scope.$digest();
+ isolatedScope = element.isolateScope().vm;
+ }));
+
+ it('should transclude the message', () => {
+ let textContainer = element[0].getElementsByTagName('p')[0];
+ let text = angular.element(textContainer).text();
+ expect(text).toEqual(message)
+ });
+
+ it('should have a close button', () => {
+ let btn = element[0].getElementsByTagName('button');
+ expect(btn.length).toEqual(1);
+ });
+
+ describe('when the close button is clicked', () => {
+ it('should hide the alert', () => {
+ let btn = element[0].getElementsByTagName('button')[0];
+ btn.click();
+ let alert = angular.element(element[0].querySelectorAll('.alert')[0]);
+ expect(alert.hasClass('ng-hide')).toBeTruthy();
+ });
+ });
+
+ describe('when autoHide is set', () => {
+
+ let to;
+
+ beforeEach(inject(($compile, $rootScope, $timeout) => {
+ scope = $rootScope.$new();
+
+ scope.config = {
+ type: 'danger',
+ closeBtn: true,
+ autoHide: 500
+ };
+
+ to = $timeout;
+
+ element = angular.element(`<xos-alert config="config">${message}</xos-alert>`);
+ $compile(element)(scope);
+ scope.$digest();
+ isolatedScope = element.isolateScope().vm;
+ }));
+
+ it('should hide the alert', () => {
+ to.flush();
+ expect(isolatedScope.show).toBeFalsy();
+ let alert = angular.element(element[0].querySelectorAll('.alert')[0]);
+ expect(alert.hasClass('ng-hide')).toBeTruthy();
+ });
+ });
+
+ describe('when show is set to false', () => {
+
+ beforeEach(inject(($compile, $rootScope) => {
+ scope = $rootScope.$new();
+
+ scope.config = {
+ type: 'danger',
+ closeBtn: true
+ };
+
+ scope.show = false;
+
+ element = angular.element(`<xos-alert config="config" show="show">${message}</xos-alert>`);
+ $compile(element)(scope);
+ scope.$digest();
+ isolatedScope = element.isolateScope().vm;
+ }));
+
+ it('should hide the alert', () => {
+ let alert = angular.element(element[0].querySelectorAll('.alert')[0]);
+ expect(alert.hasClass('ng-hide')).toBeTruthy();
+ });
+
+ describe('when show is changed to true', () => {
+ beforeEach(() => {
+ scope.show = true;
+ scope.$digest();
+ });
+
+ it('should show the alert', () => {
+ let alert = angular.element(element[0].querySelectorAll('.alert')[0]);
+ expect(alert.hasClass('ng-hide')).toBeFalsy();
+ });
+ });
+ });
+
+ });
+ });
+ });
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/table/alert.component.js b/views/ngXosLib/xosHelpers/src/ui_components/table/alert.component.js
new file mode 100644
index 0000000..7d7a026
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/src/ui_components/table/alert.component.js
@@ -0,0 +1,145 @@
+/**
+ * © OpenCORD
+ *
+ * Visit http://guide.xosproject.org/devguide/addview/ for more information
+ *
+ * Created by teone on 4/15/16.
+ */
+
+(function () {
+ 'use strict';
+
+ angular.module('xos.uiComponents')
+
+ /**
+ * @ngdoc directive
+ * @name xos.uiComponents.directive:xosAlert
+ * @restrict E
+ * @description The xos-alert directive
+ * @param {Object} config The configuration object
+ * ```
+ * {
+ * type: 'danger', //info, success, warning
+ * closeBtn: true, //default false
+ * autoHide: 3000 //delay to automatically hide the alert
+ * }
+ * ```
+ * @param {Boolean=} show Binding to show and hide the alert, default to true
+ * @element ANY
+ * @scope
+ * @example
+ <example module="sampleAlert1">
+ <file name="index.html">
+ <div ng-controller="SampleCtrl1 as vm">
+ <xos-alert config="vm.config1">
+ A sample alert message
+ </xos-alert>
+ <xos-alert config="vm.config2">
+ A sample alert message (with close button)
+ </xos-alert>
+ <xos-alert config="vm.config3">
+ A sample info message
+ </xos-alert>
+ <xos-alert config="vm.config4">
+ A sample success message
+ </xos-alert>
+ <xos-alert config="vm.config5">
+ A sample warning message
+ </xos-alert>
+ </div>
+ </file>
+ <file name="script.js">
+ angular.module('sampleAlert1', ['xos.uiComponents'])
+ .controller('SampleCtrl1', function(){
+ this.config1 = {
+ type: 'danger'
+ };
+
+ this.config2 = {
+ type: 'danger',
+ closeBtn: true
+ };
+
+ this.config3 = {
+ type: 'info'
+ };
+
+ this.config4 = {
+ type: 'success'
+ };
+
+ this.config5 = {
+ type: 'warning'
+ };
+ });
+ </file>
+ </example>
+
+ <example module="sampleAlert2">
+ <file name="index.html">
+ <div ng-controller="SampleCtrl as vm" class="row">
+ <div class="col-sm-4">
+ <a class="btn btn-default btn-block" ng-show="!vm.show" ng-click="vm.show = true">Show Alert</a>
+ <a class="btn btn-default btn-block" ng-show="vm.show" ng-click="vm.show = false">Hide Alert</a>
+ </div>
+ <div class="col-sm-8">
+ <xos-alert config="vm.config1" show="vm.show">
+ A sample alert message, not displayed by default.
+ </xos-alert>
+ </div>
+ </div>
+ </file>
+ <file name="script.js">
+ angular.module('sampleAlert2', ['xos.uiComponents'])
+ .controller('SampleCtrl', function(){
+ this.config1 = {
+ type: 'success'
+ };
+
+ this.show = false;
+ });
+ </file>
+ </example>
+ **/
+
+ .directive('xosAlert', function(){
+ return {
+ restrict: 'E',
+ scope: {
+ config: '=',
+ show: '=?'
+ },
+ template: `
+ <div class="alert alert-{{vm.config.type}}" ng-show="vm.show">
+ <button type="button" class="close" ng-if="vm.config.closeBtn" ng-click="vm.dismiss()">
+ <span aria-hidden="true">×</span>
+ </button>
+ <p ng-transclude></p>
+ </div>
+ `,
+ transclude: true,
+ bindToController: true,
+ controllerAs: 'vm',
+ controller: function($timeout){
+
+ if(!this.config){
+ throw new Error('[xosAlert] Please provide a configuration via the "config" attribute');
+ }
+
+ // default the value to true
+ this.show = this.show !== false;
+
+ this.dismiss = () => {
+ this.show = false;
+ }
+
+ if(this.config.autoHide){
+ let to = $timeout(() => {
+ this.dismiss();
+ $timeout.cancel(to);
+ }, this.config.autoHide);
+ }
+ }
+ }
+ })
+})();
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/table/pagination.component.js b/views/ngXosLib/xosHelpers/src/ui_components/table/pagination.component.js
index 6266303..b7b1701 100644
--- a/views/ngXosLib/xosHelpers/src/ui_components/table/pagination.component.js
+++ b/views/ngXosLib/xosHelpers/src/ui_components/table/pagination.component.js
@@ -106,7 +106,6 @@
this.pages = Math.ceil(this.totalElements / this.pageSize);
this.pageList = this.createPages(this.pages);
}
- // scope.getPages();
});
}
}
diff --git a/views/ngXosViews/sampleView/src/js/main.js b/views/ngXosViews/sampleView/src/js/main.js
index 798cb0e..b00aa0b 100644
--- a/views/ngXosViews/sampleView/src/js/main.js
+++ b/views/ngXosViews/sampleView/src/js/main.js
@@ -59,6 +59,12 @@
// }
};
+ this.alertConfig = {
+ type: 'danger',
+ closeBtn: true
+ }
+
+
// retrieving user list
Users.query().$promise
.then((users) => {
diff --git a/views/ngXosViews/sampleView/src/templates/users-list.tpl.html b/views/ngXosViews/sampleView/src/templates/users-list.tpl.html
index 10d7208..c0c58cb 100644
--- a/views/ngXosViews/sampleView/src/templates/users-list.tpl.html
+++ b/views/ngXosViews/sampleView/src/templates/users-list.tpl.html
@@ -5,6 +5,8 @@
</div>
</div>
+ <xos-alert config="vm.alertConfig">Alert message Here</xos-alert>
+
<div class="row">
<div class="col-xs-12">
<xos-table data="vm.users" config="vm.tableConfig"></xos-table>