From a35368f55884bfe12da98496107b949ad7d49944 Mon Sep 17 00:00:00 2001
From: Jared Tabor
Date: Fri, 4 Mar 2016 15:39:23 -0800
Subject: [PATCH] Adding initial notifications files
---
awx/ui/client/src/app.js | 8 +-
.../src/notifications/add/add.controller.js | 67 +++++++++++++
.../src/notifications/add/add.partial.html | 3 +
.../client/src/notifications/add/add.route.js | 23 +++++
awx/ui/client/src/notifications/add/main.js | 15 +++
.../src/notifications/edit/edit.controller.js | 97 +++++++++++++++++++
.../src/notifications/edit/edit.partial.html | 3 +
.../src/notifications/edit/edit.route.js | 23 +++++
awx/ui/client/src/notifications/edit/main.js | 15 +++
.../src/notifications/list/list.controller.js | 83 ++++++++++++++++
.../src/notifications/list/list.partial.html | 4 +
.../src/notifications/list/list.route.js | 19 ++++
awx/ui/client/src/notifications/list/main.js | 15 +++
awx/ui/client/src/notifications/main.js | 22 +++++
.../src/notifications/notifications.form.js | 47 +++++++++
.../src/notifications/notifications.list.js | 63 ++++++++++++
.../src/setup-menu/setup-menu.partial.html | 6 ++
17 files changed, 510 insertions(+), 3 deletions(-)
create mode 100644 awx/ui/client/src/notifications/add/add.controller.js
create mode 100644 awx/ui/client/src/notifications/add/add.partial.html
create mode 100644 awx/ui/client/src/notifications/add/add.route.js
create mode 100644 awx/ui/client/src/notifications/add/main.js
create mode 100644 awx/ui/client/src/notifications/edit/edit.controller.js
create mode 100644 awx/ui/client/src/notifications/edit/edit.partial.html
create mode 100644 awx/ui/client/src/notifications/edit/edit.route.js
create mode 100644 awx/ui/client/src/notifications/edit/main.js
create mode 100644 awx/ui/client/src/notifications/list/list.controller.js
create mode 100644 awx/ui/client/src/notifications/list/list.partial.html
create mode 100644 awx/ui/client/src/notifications/list/list.route.js
create mode 100644 awx/ui/client/src/notifications/list/main.js
create mode 100644 awx/ui/client/src/notifications/main.js
create mode 100644 awx/ui/client/src/notifications/notifications.form.js
create mode 100644 awx/ui/client/src/notifications/notifications.list.js
diff --git a/awx/ui/client/src/app.js b/awx/ui/client/src/app.js
index 3c12eadfb1..a37db8cbc4 100644
--- a/awx/ui/client/src/app.js
+++ b/awx/ui/client/src/app.js
@@ -30,6 +30,7 @@ import inventoryScripts from './inventory-scripts/main';
import permissions from './permissions/main';
import managementJobs from './management-jobs/main';
import jobDetail from './job-detail/main';
+import notifications from './notifications/main';
// modules
import about from './about/main';
@@ -98,6 +99,7 @@ var tower = angular.module('Tower', [
activityStream.name,
footer.name,
jobDetail.name,
+ notifications.name,
standardOut.name,
'templates',
'Utilities',
@@ -882,13 +884,13 @@ var tower = angular.module('Tower', [
}]);
}])
- .run(['$q', '$compile', '$cookieStore', '$rootScope', '$log', '$state', 'CheckLicense',
+ .run(['$q', '$compile', '$cookieStore', '$rootScope', '$log', '$state', 'CheckLicense',
'$location', 'Authorization', 'LoadBasePaths', 'Timer', 'ClearScope', 'Socket',
'LoadConfig', 'Store', 'ShowSocketHelp', 'pendoService',
function (
- $q, $compile, $cookieStore, $rootScope, $log, $state, CheckLicense,
+ $q, $compile, $cookieStore, $rootScope, $log, $state, CheckLicense,
$location, Authorization, LoadBasePaths, Timer, ClearScope, Socket,
- LoadConfig, Store, ShowSocketHelp, pendoService)
+ LoadConfig, Store, ShowSocketHelp, pendoService)
{
var sock;
diff --git a/awx/ui/client/src/notifications/add/add.controller.js b/awx/ui/client/src/notifications/add/add.controller.js
new file mode 100644
index 0000000000..88048941ff
--- /dev/null
+++ b/awx/ui/client/src/notifications/add/add.controller.js
@@ -0,0 +1,67 @@
+/*************************************************
+ * Copyright (c) 2015 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+export default
+ [ '$rootScope', 'pagination', '$compile','SchedulerInit', 'Rest', 'Wait',
+ 'notificationsFormObject', 'ProcessErrors', 'GetBasePath', 'Empty',
+ 'GenerateForm', 'SearchInit' , 'PaginateInit',
+ 'LookUpInit', 'OrganizationList', '$scope', '$state',
+ function(
+ $rootScope, pagination, $compile, SchedulerInit, Rest, Wait,
+ notificationsFormObject, ProcessErrors, GetBasePath, Empty,
+ GenerateForm, SearchInit, PaginateInit,
+ LookUpInit, OrganizationList, $scope, $state
+ ) {
+ var scope = $scope,
+ generator = GenerateForm,
+ form = notificationsFormObject,
+ url = GetBasePath('notifications');
+
+ generator.inject(form, {
+ mode: 'add' ,
+ scope:scope,
+ related: false
+ });
+ generator.reset();
+
+ LookUpInit({
+ url: GetBasePath('organization'),
+ scope: scope,
+ form: form,
+ list: OrganizationList,
+ field: 'organization',
+ input_type: 'radio'
+ });
+
+ // Save
+ scope.formSave = function () {
+
+ generator.clearApiErrors();
+ Wait('start');
+ Rest.setUrl(url);
+ Rest.post({
+ name: scope.name,
+ description: scope.description,
+ organization: scope.organization,
+ script: scope.script
+ })
+ .success(function (data) {
+ $rootScope.addedItem = data.id;
+ $state.go('inventoryScripts', {}, {reload: true});
+ Wait('stop');
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, form, { hdr: 'Error!',
+ msg: 'Failed to add new inventory script. POST returned status: ' + status });
+ });
+ };
+
+ scope.formCancel = function () {
+ $state.transitionTo('inventoryScripts');
+ };
+
+ }
+ ];
diff --git a/awx/ui/client/src/notifications/add/add.partial.html b/awx/ui/client/src/notifications/add/add.partial.html
new file mode 100644
index 0000000000..65bfebbbe6
--- /dev/null
+++ b/awx/ui/client/src/notifications/add/add.partial.html
@@ -0,0 +1,3 @@
+
diff --git a/awx/ui/client/src/notifications/add/add.route.js b/awx/ui/client/src/notifications/add/add.route.js
new file mode 100644
index 0000000000..6bad062844
--- /dev/null
+++ b/awx/ui/client/src/notifications/add/add.route.js
@@ -0,0 +1,23 @@
+/*************************************************
+ * Copyright (c) 2015 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+import {templateUrl} from '../../shared/template-url/template-url.factory';
+
+export default {
+ name: 'notifications.add',
+ route: '/add',
+ templateUrl: templateUrl('notifications/add/add'),
+ controller: 'notificationsAddController',
+ resolve: {
+ features: ['FeaturesService', function(FeaturesService) {
+ return FeaturesService.get();
+ }]
+ },
+ ncyBreadcrumb: {
+ parent: 'notifications',
+ label: 'Create Notification'
+ }
+};
diff --git a/awx/ui/client/src/notifications/add/main.js b/awx/ui/client/src/notifications/add/main.js
new file mode 100644
index 0000000000..f3101e402f
--- /dev/null
+++ b/awx/ui/client/src/notifications/add/main.js
@@ -0,0 +1,15 @@
+/*************************************************
+ * Copyright (c) 2015 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+import route from './add.route';
+import controller from './add.controller';
+
+export default
+ angular.module('notificationsAdd', [])
+ .controller('notificationsAddController', controller)
+ .run(['$stateExtender', function($stateExtender) {
+ $stateExtender.addState(route);
+ }]);
diff --git a/awx/ui/client/src/notifications/edit/edit.controller.js b/awx/ui/client/src/notifications/edit/edit.controller.js
new file mode 100644
index 0000000000..a14b3334af
--- /dev/null
+++ b/awx/ui/client/src/notifications/edit/edit.controller.js
@@ -0,0 +1,97 @@
+/*************************************************
+ * Copyright (c) 2015 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+export default
+ [ 'Rest', 'Wait',
+ 'notificationsFormObject', 'ProcessErrors', 'GetBasePath',
+ 'GenerateForm', 'SearchInit' , 'PaginateInit',
+ 'LookUpInit', 'OrganizationList', 'inventory_script',
+ '$scope', '$state',
+ function(
+ Rest, Wait,
+ notificationsFormObject, ProcessErrors, GetBasePath,
+ GenerateForm, SearchInit, PaginateInit,
+ LookUpInit, OrganizationList, inventory_script,
+ $scope, $state
+ ) {
+ var generator = GenerateForm,
+ id = inventory_script.id,
+ form = notificationsFormObject,
+ master = {},
+ url = GetBasePath('notifications');
+
+ $scope.inventory_script = inventory_script;
+ generator.inject(form, {
+ mode: 'edit' ,
+ scope:$scope,
+ related: false,
+ activityStream: false
+ });
+ generator.reset();
+ LookUpInit({
+ url: GetBasePath('organization'),
+ scope: $scope,
+ form: form,
+ // hdr: "Select Custom Inventory",
+ list: OrganizationList,
+ field: 'organization',
+ input_type: 'radio'
+ });
+
+ // Retrieve detail record and prepopulate the form
+ Wait('start');
+ Rest.setUrl(url + id+'/');
+ Rest.get()
+ .success(function (data) {
+ var fld;
+ for (fld in form.fields) {
+ if (data[fld]) {
+ $scope[fld] = data[fld];
+ master[fld] = data[fld];
+ }
+
+ if (form.fields[fld].sourceModel && data.summary_fields &&
+ data.summary_fields[form.fields[fld].sourceModel]) {
+ $scope[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
+ data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
+ master[form.fields[fld].sourceModel + '_' + form.fields[fld].sourceField] =
+ data.summary_fields[form.fields[fld].sourceModel][form.fields[fld].sourceField];
+ }
+ }
+ Wait('stop');
+ })
+ .error(function (data, status) {
+ ProcessErrors($scope, data, status, form, { hdr: 'Error!',
+ msg: 'Failed to retrieve inventory script: ' + id + '. GET status: ' + status });
+ });
+
+ $scope.formSave = function () {
+ generator.clearApiErrors();
+ Wait('start');
+ Rest.setUrl(url+ id+'/');
+ Rest.put({
+ name: $scope.name,
+ description: $scope.description,
+ organization: $scope.organization,
+ script: $scope.script
+ })
+ .success(function () {
+ $state.transitionTo('inventoryScriptsList');
+ Wait('stop');
+
+ })
+ .error(function (data, status) {
+ ProcessErrors($scope, data, status, form, { hdr: 'Error!',
+ msg: 'Failed to add new inventory script. PUT returned status: ' + status });
+ });
+ };
+
+ $scope.formCancel = function () {
+ $state.transitionTo('inventoryScripts');
+ };
+
+ }
+ ];
diff --git a/awx/ui/client/src/notifications/edit/edit.partial.html b/awx/ui/client/src/notifications/edit/edit.partial.html
new file mode 100644
index 0000000000..ebd7e80e80
--- /dev/null
+++ b/awx/ui/client/src/notifications/edit/edit.partial.html
@@ -0,0 +1,3 @@
+
diff --git a/awx/ui/client/src/notifications/edit/edit.route.js b/awx/ui/client/src/notifications/edit/edit.route.js
new file mode 100644
index 0000000000..1987b32cad
--- /dev/null
+++ b/awx/ui/client/src/notifications/edit/edit.route.js
@@ -0,0 +1,23 @@
+/*************************************************
+ * Copyright (c) 2015 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+import {templateUrl} from '../../shared/template-url/template-url.factory';
+
+export default {
+ name: 'notifications.edit',
+ route: '/edit',
+ templateUrl: templateUrl('notifications/edit/edit'),
+ controller: 'notificationsEditController',
+ resolve: {
+ features: ['FeaturesService', function(FeaturesService) {
+ return FeaturesService.get();
+ }]
+ },
+ ncyBreadcrumb: {
+ parent: 'notifications',
+ label: 'Edit Notification'
+ }
+};
diff --git a/awx/ui/client/src/notifications/edit/main.js b/awx/ui/client/src/notifications/edit/main.js
new file mode 100644
index 0000000000..8f0c62d7a1
--- /dev/null
+++ b/awx/ui/client/src/notifications/edit/main.js
@@ -0,0 +1,15 @@
+/*************************************************
+ * Copyright (c) 2015 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+import route from './edit.route';
+import controller from './edit.controller';
+
+export default
+ angular.module('notificationsEdit', [])
+ .controller('notificationsEditController', controller)
+ .run(['$stateExtender', function($stateExtender) {
+ $stateExtender.addState(route);
+ }]);
diff --git a/awx/ui/client/src/notifications/list/list.controller.js b/awx/ui/client/src/notifications/list/list.controller.js
new file mode 100644
index 0000000000..df0ef9f7d2
--- /dev/null
+++ b/awx/ui/client/src/notifications/list/list.controller.js
@@ -0,0 +1,83 @@
+/*************************************************
+ * Copyright (c) 2015 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+export default
+ [ '$rootScope','Wait', 'generateList', 'notificationsListObject',
+ 'GetBasePath' , 'SearchInit' , 'PaginateInit',
+ 'Rest' , 'ProcessErrors', 'Prompt', '$state',
+ function(
+ $rootScope,Wait, GenerateList, notificationsListObject,
+ GetBasePath, SearchInit, PaginateInit,
+ Rest, ProcessErrors, Prompt, $state
+ ) {
+ var scope = $rootScope.$new(),
+ defaultUrl = GetBasePath('notifications'),
+ list = notificationsListObject,
+ view = GenerateList;
+
+ view.inject( list, {
+ mode: 'edit',
+ scope: scope
+ });
+
+ // SearchInit({
+ // scope: scope,
+ // set: 'notifications',
+ // list: list,
+ // url: defaultUrl
+ // });
+ //
+ // if ($rootScope.addedItem) {
+ // scope.addedItem = $rootScope.addedItem;
+ // delete $rootScope.addedItem;
+ // }
+ // PaginateInit({
+ // scope: scope,
+ // list: list,
+ // url: defaultUrl
+ // });
+ //
+ // scope.search(list.iterator);
+
+ scope.editNotification = function(){
+ $state.transitionTo('notifications.edit',{
+ inventory_script_id: this.inventory_script.id,
+ inventory_script: this.inventory_script
+ });
+ };
+
+ scope.deleteNotification = function(id, name){
+
+ var action = function () {
+ $('#prompt-modal').modal('hide');
+ Wait('start');
+ var url = defaultUrl + id + '/';
+ Rest.setUrl(url);
+ Rest.destroy()
+ .success(function () {
+ scope.search(list.iterator);
+ })
+ .error(function (data, status) {
+ ProcessErrors(scope, data, status, null, { hdr: 'Error!',
+ msg: 'Call to ' + url + ' failed. DELETE returned status: ' + status });
+ });
+ };
+
+ var bodyHtml = 'Are you sure you want to delete the inventory script below?
' + name + '
';
+ Prompt({
+ hdr: 'Delete',
+ body: bodyHtml,
+ action: action,
+ actionText: 'DELETE'
+ });
+ };
+
+ scope.addNotification = function(){
+ $state.transitionTo('notifications.add');
+ };
+
+ }
+ ];
diff --git a/awx/ui/client/src/notifications/list/list.partial.html b/awx/ui/client/src/notifications/list/list.partial.html
new file mode 100644
index 0000000000..bad2fa18bb
--- /dev/null
+++ b/awx/ui/client/src/notifications/list/list.partial.html
@@ -0,0 +1,4 @@
+
diff --git a/awx/ui/client/src/notifications/list/list.route.js b/awx/ui/client/src/notifications/list/list.route.js
new file mode 100644
index 0000000000..da76880791
--- /dev/null
+++ b/awx/ui/client/src/notifications/list/list.route.js
@@ -0,0 +1,19 @@
+/*************************************************
+ * Copyright (c) 2015 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+import {templateUrl} from '../../shared/template-url/template-url.factory';
+
+export default {
+ name: 'notifications',
+ route: '/notifications',
+ templateUrl: templateUrl('notifications/list/list'),
+ controller: 'notificationsListController',
+ resolve: {
+ features: ['FeaturesService', function(FeaturesService) {
+ return FeaturesService.get();
+ }]
+ }
+};
diff --git a/awx/ui/client/src/notifications/list/main.js b/awx/ui/client/src/notifications/list/main.js
new file mode 100644
index 0000000000..35cab03cef
--- /dev/null
+++ b/awx/ui/client/src/notifications/list/main.js
@@ -0,0 +1,15 @@
+/*************************************************
+ * Copyright (c) 2015 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+import route from './list.route';
+import controller from './list.controller';
+
+export default
+ angular.module('notificationsList', [])
+ .controller('notificationsListController', controller)
+ .run(['$stateExtender', function($stateExtender) {
+ $stateExtender.addState(route);
+ }]);
diff --git a/awx/ui/client/src/notifications/main.js b/awx/ui/client/src/notifications/main.js
new file mode 100644
index 0000000000..147b3b8479
--- /dev/null
+++ b/awx/ui/client/src/notifications/main.js
@@ -0,0 +1,22 @@
+/*************************************************
+ * Copyright (c) 2016 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+
+import notificationsList from './list/main';
+import notificationsAdd from './add/main';
+import notificationsEdit from './edit/main';
+
+import list from './notifications.list';
+import form from './notifications.form';
+
+export default
+ angular.module('notifications', [
+ notificationsList.name,
+ notificationsAdd.name,
+ notificationsEdit.name
+ ])
+ .factory('notificationsListObject', list)
+ .factory('notificationsFormObject', form);
diff --git a/awx/ui/client/src/notifications/notifications.form.js b/awx/ui/client/src/notifications/notifications.form.js
new file mode 100644
index 0000000000..d8c49d00ba
--- /dev/null
+++ b/awx/ui/client/src/notifications/notifications.form.js
@@ -0,0 +1,47 @@
+/*************************************************
+ * Copyright (c) 2015 Ansible, Inc.
+ *
+ * All Rights Reserved
+ *************************************************/
+
+ /**
+ * @ngdoc function
+ * @name forms.function:CustomInventory
+ * @description This form is for adding/editing an organization
+*/
+
+export default function() {
+ return {
+
+ addTitle: 'New Notification',
+ editTitle: '{{ name }}',
+ name: 'notification',
+ showActions: true,
+
+ fields: {
+ name: {
+ label: 'Name',
+ type: 'text',
+ addRequired: true,
+ editRequired: true,
+ capitalize: false
+ },
+ description: {
+ label: 'Description',
+ type: 'text',
+ addRequired: false,
+ editRequired: false
+ }
+ },
+
+ buttons: { //for now always generates
+
+ Notifications
+
+ Create templates for sending notifications with Email, HipChat, Slack, and SMS.
+
+
View Your License