mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 23:07:42 -02:30
Extract factory for generating template URLs
This commit is contained in:
@@ -38,6 +38,7 @@ import mainMenu from 'tower/main-menu/main';
|
|||||||
import browserData from 'tower/browser-data/main';
|
import browserData from 'tower/browser-data/main';
|
||||||
import dashboard from 'tower/dashboard/main';
|
import dashboard from 'tower/dashboard/main';
|
||||||
import moment from 'tower/shared/moment/main';
|
import moment from 'tower/shared/moment/main';
|
||||||
|
import templateUrl from 'tower/shared/template-url/main';
|
||||||
|
|
||||||
import {JobDetailController} from 'tower/controllers/JobDetail';
|
import {JobDetailController} from 'tower/controllers/JobDetail';
|
||||||
import {JobStdoutController} from 'tower/controllers/JobStdout';
|
import {JobStdoutController} from 'tower/controllers/JobStdout';
|
||||||
@@ -84,6 +85,7 @@ var tower = angular.module('Tower', [
|
|||||||
mainMenu.name,
|
mainMenu.name,
|
||||||
dashboard.name,
|
dashboard.name,
|
||||||
moment.name,
|
moment.name,
|
||||||
|
templateUrl.name,
|
||||||
'AuthService',
|
'AuthService',
|
||||||
'Utilities',
|
'Utilities',
|
||||||
'LicenseHelper',
|
'LicenseHelper',
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
/* jshint unused: vars */
|
/* jshint unused: vars */
|
||||||
export default
|
export default
|
||||||
[ '$rootScope',
|
[ 'templateUrl',
|
||||||
function() {
|
function(templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
scope: {
|
scope: {
|
||||||
data: '='
|
data: '='
|
||||||
},
|
},
|
||||||
replace: false,
|
replace: false,
|
||||||
templateUrl: '/static/js/dashboard/counts/dashboard-counts.partial.html',
|
templateUrl: templateUrl('dashboard/counts/dashboard-counts'),
|
||||||
link: function(scope, element, attrs) {
|
link: function(scope, element, attrs) {
|
||||||
scope.$watch("data", function(data) {
|
scope.$watch("data", function(data) {
|
||||||
if (data && data.hosts) {
|
if (data && data.hosts) {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
/* jshint unused: vars */
|
/* jshint unused: vars */
|
||||||
export default
|
export default
|
||||||
[ '$rootScope',
|
[ 'templateUrl',
|
||||||
function() {
|
function(templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
scope: true,
|
scope: true,
|
||||||
templateUrl: '/static/js/dashboard/dashboard.partial.html',
|
templateUrl: templateUrl('dashboard/dashboard'),
|
||||||
link: function(scope, element, attrs) {
|
link: function(scope, element, attrs) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
/* jshint unused: vars */
|
/* jshint unused: vars */
|
||||||
export default
|
export default
|
||||||
[ '$rootScope',
|
[ 'templateUrl',
|
||||||
function() {
|
function(templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
scope: true,
|
scope: true,
|
||||||
templateUrl: '/static/js/dashboard/graphs/dashboard-graphs.partial.html',
|
templateUrl: templateUrl('dashboard/graphs/dashboard-graphs'),
|
||||||
link: function(scope, element, attrs) {
|
link: function(scope, element, attrs) {
|
||||||
function clearGraphs() {
|
function clearGraphs() {
|
||||||
scope.jobStatusSelected = false;
|
scope.jobStatusSelected = false;
|
||||||
|
|||||||
@@ -8,14 +8,15 @@
|
|||||||
[ '$compile',
|
[ '$compile',
|
||||||
'$window',
|
'$window',
|
||||||
'adjustGraphSize',
|
'adjustGraphSize',
|
||||||
|
'templateUrl',
|
||||||
HostStatusGraph,
|
HostStatusGraph,
|
||||||
];
|
];
|
||||||
|
|
||||||
function HostStatusGraph($compile, $window, adjustGraphSize) {
|
function HostStatusGraph($compile, $window, adjustGraphSize, templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
link: link,
|
link: link,
|
||||||
templateUrl: '/static/js/dashboard/graphs/host-status/host_status_graph.partial.html'
|
templateUrl: templateUrl('dashboard/graphs/host-status/host_status_graph')
|
||||||
};
|
};
|
||||||
|
|
||||||
function link(scope, element, attr) {
|
function link(scope, element, attr) {
|
||||||
|
|||||||
@@ -12,16 +12,17 @@
|
|||||||
'Wait',
|
'Wait',
|
||||||
'adjustGraphSize',
|
'adjustGraphSize',
|
||||||
'jobStatusGraphData',
|
'jobStatusGraphData',
|
||||||
|
'templateUrl',
|
||||||
JobStatusGraph
|
JobStatusGraph
|
||||||
];
|
];
|
||||||
|
|
||||||
function JobStatusGraph($rootScope, $compile , $location, $window, Wait, adjustGraphSize, graphDataService) {
|
function JobStatusGraph($rootScope, $compile , $location, $window, Wait, adjustGraphSize, graphDataService, templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
scope: {
|
scope: {
|
||||||
data: '='
|
data: '='
|
||||||
},
|
},
|
||||||
templateUrl: '/static/js/dashboard/graphs/job-status/job_status_graph.partial.html',
|
templateUrl: templateUrl('dashboard/graphs/job-status/job_status_graph'),
|
||||||
link: link
|
link: link
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import JobStatusGraphDirective from 'tower/dashboard/graphs/job-status/job-status-graph.directive';
|
import JobStatusGraphDirective from 'tower/dashboard/graphs/job-status/job-status-graph.directive';
|
||||||
import JobStatusGraphService from 'tower/dashboard/graphs/job-status/job-status-graph.service';
|
import JobStatusGraphService from 'tower/dashboard/graphs/job-status/job-status-graph.service';
|
||||||
import DashboardGraphHelpers from 'tower/dashboard/graphs/graph-helpers/main';
|
import DashboardGraphHelpers from 'tower/dashboard/graphs/graph-helpers/main';
|
||||||
import ApiLoader from 'tower/shared/api-loader';
|
import templateUrl from 'tower/shared/template-url/main';
|
||||||
|
|
||||||
export default angular.module('JobStatusGraph', [DashboardGraphHelpers.name, ApiLoader.name])
|
export default angular.module('JobStatusGraph', [DashboardGraphHelpers.name, templateUrl.name])
|
||||||
.directive('jobStatusGraph', JobStatusGraphDirective)
|
.directive('jobStatusGraph', JobStatusGraphDirective)
|
||||||
.service('jobStatusGraphData', JobStatusGraphService);
|
.service('jobStatusGraphData', JobStatusGraphService);
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
/* jshint unused: vars */
|
/* jshint unused: vars */
|
||||||
export default
|
export default
|
||||||
[ "PlaybookRun",
|
[ "PlaybookRun",
|
||||||
function JobTemplatesList(PlaybookRun) {
|
'templateUrl',
|
||||||
|
function JobTemplatesList(PlaybookRun, templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
link: link,
|
link: link,
|
||||||
scope: {
|
scope: {
|
||||||
data: '='
|
data: '='
|
||||||
},
|
},
|
||||||
templateUrl: '/static/js/dashboard/lists/job-templates/job-templates-list.partial.html'
|
templateUrl: templateUrl('dashboard/lists/job-templates/job-templates-list')
|
||||||
};
|
};
|
||||||
|
|
||||||
function link(scope, element, attr) {
|
function link(scope, element, attr) {
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
/* jshint unused: vars */
|
/* jshint unused: vars */
|
||||||
export default
|
export default
|
||||||
['moment',
|
[ 'moment',
|
||||||
function JobsList(moment) {
|
'templateUrl',
|
||||||
|
function JobsList(moment, templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
link: link,
|
link: link,
|
||||||
scope: {
|
scope: {
|
||||||
data: '='
|
data: '='
|
||||||
},
|
},
|
||||||
templateUrl: '/static/js/dashboard/lists/jobs/jobs-list.partial.html'
|
templateUrl: templateUrl('dashboard/lists/jobs/jobs-list')
|
||||||
};
|
};
|
||||||
|
|
||||||
function link(scope, element, attr) {
|
function link(scope, element, attr) {
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
export default function() {
|
export default
|
||||||
|
[ 'templateUrl',
|
||||||
|
function(templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
templateUrl: '/static/js/main-menu/menu-default.partial.html',
|
templateUrl: templateUrl('main-menu/menu-default'),
|
||||||
link: function(scope, element) {
|
link: function(scope, element) {
|
||||||
var contents = element.contents();
|
var contents = element.contents();
|
||||||
contents.unwrap();
|
contents.unwrap();
|
||||||
@@ -12,4 +14,5 @@ export default function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
];
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
/* jshint unused: vars */
|
/* jshint unused: vars */
|
||||||
|
|
||||||
export default function() {
|
export default
|
||||||
|
[ 'templateUrl',
|
||||||
|
function(templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
controllerAs: 'mainMenu',
|
controllerAs: 'mainMenu',
|
||||||
templateUrl: '/static/js/main-menu/main-menu.partial.html',
|
templateUrl: templateUrl('main-menu/main-menu'),
|
||||||
controller: ['$scope', function($scope) {
|
controller: ['$scope', function($scope) {
|
||||||
this.open = function() {
|
this.open = function() {
|
||||||
$scope.isOpen = true;
|
$scope.isOpen = true;
|
||||||
@@ -42,4 +44,5 @@ export default function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
];
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
/* jshint unused: vars */
|
/* jshint unused: vars */
|
||||||
|
|
||||||
export default function() {
|
export default
|
||||||
|
[ 'templateUrl',
|
||||||
|
function(templateUrl) {
|
||||||
return {
|
return {
|
||||||
templateUrl: '/static/js/main-menu/menu-toggle.partial.html',
|
templateUrl: templateUrl('main-menu/menu-toggle'),
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
require: '^^mainMenu',
|
require: '^^mainMenu',
|
||||||
scope: {
|
scope: {
|
||||||
@@ -24,4 +26,5 @@ export default function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
];
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
export default function() {
|
export default
|
||||||
|
[ 'templateUrl',
|
||||||
|
function(templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
templateUrl: '/static/js/main-menu/menu-portal.partial.html',
|
templateUrl: templateUrl('main-menu/menu-portal'),
|
||||||
link: function(scope, element) {
|
link: function(scope, element) {
|
||||||
var contents = element.contents();
|
var contents = element.contents();
|
||||||
contents.unwrap();
|
contents.unwrap();
|
||||||
@@ -12,4 +14,5 @@ export default function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
];
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
/* jshint unused: vars */
|
/* jshint unused: vars */
|
||||||
|
|
||||||
export default ['$rootScope', function($rootScope) {
|
export default
|
||||||
|
[ '$rootScope',
|
||||||
|
'templateUrl',
|
||||||
|
function($rootScope, templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
templateUrl: '/static/js/main-menu/web-socket-status.partial.html',
|
templateUrl: templateUrl('main-menu/web-socket-status'),
|
||||||
link: function(scope, element, attrs) {
|
link: function(scope, element, attrs) {
|
||||||
scope.socketHelp = $rootScope.socketHelp;
|
scope.socketHelp = $rootScope.socketHelp;
|
||||||
scope.socketTip = $rootScope.socketTip;
|
scope.socketTip = $rootScope.socketTip;
|
||||||
@@ -15,4 +18,5 @@ export default ['$rootScope', function($rootScope) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}];
|
}
|
||||||
|
];
|
||||||
|
|||||||
@@ -9,13 +9,15 @@
|
|||||||
import controller from './breadcrumbs.controller';
|
import controller from './breadcrumbs.controller';
|
||||||
import 'tower/shared/generator-helpers';
|
import 'tower/shared/generator-helpers';
|
||||||
|
|
||||||
export default function() {
|
export default
|
||||||
|
[ 'templateUrl',
|
||||||
|
function(templateUrl) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
controller: controller,
|
controller: controller,
|
||||||
transclude: true,
|
transclude: true,
|
||||||
templateUrl: '/static/js/shared/breadcrumbs/breadcrumbs.partial.html',
|
templateUrl: templateUrl('shared/breadcrumbs/breadcrumbs'),
|
||||||
scope: {
|
scope: {
|
||||||
},
|
},
|
||||||
link: function(scope, element, attrs, controller) {
|
link: function(scope, element, attrs, controller) {
|
||||||
@@ -35,4 +37,5 @@ export default function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
];
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
export default function() {
|
export default
|
||||||
|
[ 'templateUrl',
|
||||||
|
function(templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
templateUrl: '/static/js/shared/icon/icon.partial.html',
|
templateUrl: templateUrl('shared/icon/icon'),
|
||||||
scope: {
|
scope: {
|
||||||
},
|
},
|
||||||
link: function(scope, element, attrs) {
|
link: function(scope, element, attrs) {
|
||||||
@@ -26,4 +28,5 @@ export default function() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
];
|
||||||
|
|||||||
@@ -7,9 +7,10 @@
|
|||||||
import multiSelect from './multi-select-list.directive';
|
import multiSelect from './multi-select-list.directive';
|
||||||
import selectAll from './select-all.directive';
|
import selectAll from './select-all.directive';
|
||||||
import selectListItem from './select-list-item.directive';
|
import selectListItem from './select-list-item.directive';
|
||||||
|
import templateUrl from 'tower/shared/template-url/main';
|
||||||
|
|
||||||
export default
|
export default
|
||||||
angular.module('multiSelectList', [])
|
angular.module('multiSelectList', [templateUrl.name])
|
||||||
.directive('multiSelectList', multiSelect)
|
.directive('multiSelectList', multiSelect)
|
||||||
.directive('selectAll', selectAll)
|
.directive('selectAll', selectAll)
|
||||||
.directive('selectListItem', selectListItem);
|
.directive('selectListItem', selectListItem);
|
||||||
|
|||||||
@@ -129,12 +129,10 @@
|
|||||||
// // =>
|
// // =>
|
||||||
// '/static/js/shared/multi-select-list/select-all.html
|
// '/static/js/shared/multi-select-list/select-all.html
|
||||||
//
|
//
|
||||||
function template(base) {
|
|
||||||
return '/static/js/' + base + '.partial.html';
|
|
||||||
}
|
|
||||||
|
|
||||||
export default
|
export default
|
||||||
[ function() {
|
[ 'templateUrl',
|
||||||
|
function(templateUrl) {
|
||||||
return {
|
return {
|
||||||
require: '^multiSelectList',
|
require: '^multiSelectList',
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
@@ -145,7 +143,7 @@ export default
|
|||||||
extendedLabel: '&',
|
extendedLabel: '&',
|
||||||
isSelectionEmpty: '=selectionsEmpty'
|
isSelectionEmpty: '=selectionsEmpty'
|
||||||
},
|
},
|
||||||
templateUrl: template('shared/multi-select-list/select-all'),
|
templateUrl: templateUrl('shared/multi-select-list/select-all'),
|
||||||
link: function(scope, element, attrs, controller) {
|
link: function(scope, element, attrs, controller) {
|
||||||
|
|
||||||
scope.label = scope.label || 'All';
|
scope.label = scope.label || 'All';
|
||||||
|
|||||||
6
awx/ui/static/js/shared/template-url/main.js
Normal file
6
awx/ui/static/js/shared/template-url/main.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import templateUrl from './template-url.factory';
|
||||||
|
|
||||||
|
export default
|
||||||
|
angular.module('templateUrl', [])
|
||||||
|
.factory('templateUrl', templateUrl);
|
||||||
|
|
||||||
20
awx/ui/static/js/shared/template-url/template-url.factory.js
Normal file
20
awx/ui/static/js/shared/template-url/template-url.factory.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
function templateUrl($sce, path, isTrusted) {
|
||||||
|
isTrusted = isTrusted !== false; // defaults to true, can be passed in as false
|
||||||
|
var parts = ['', 'static', 'js'];
|
||||||
|
parts.push(path);
|
||||||
|
|
||||||
|
var url = parts.join('/') + '.partial.html';
|
||||||
|
|
||||||
|
if (isTrusted) {
|
||||||
|
url = $sce.trustAsResourceUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default
|
||||||
|
[ '$sce',
|
||||||
|
function($sce) {
|
||||||
|
return _.partial(templateUrl, $sce);
|
||||||
|
}
|
||||||
|
];
|
||||||
@@ -8,7 +8,8 @@
|
|||||||
|
|
||||||
export default
|
export default
|
||||||
[ 'moment',
|
[ 'moment',
|
||||||
function(moment) {
|
'templateUrl',
|
||||||
|
function(moment, templateUrl) {
|
||||||
return {
|
return {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
scope: {
|
scope: {
|
||||||
@@ -17,7 +18,7 @@ export default
|
|||||||
autoUpdate: '=?',
|
autoUpdate: '=?',
|
||||||
inputClass: '&'
|
inputClass: '&'
|
||||||
},
|
},
|
||||||
templateUrl: '/static/js/system-tracking/date-picker/date-picker.partial.html',
|
templateUrl: templateUrl('system-tracking/date-picker/date-picker'),
|
||||||
link: function(scope, element, attrs) {
|
link: function(scope, element, attrs) {
|
||||||
|
|
||||||
// We need to make sure this _never_ recurses, which sometimes happens
|
// We need to make sure this _never_ recurses, which sometimes happens
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
/* jshint unused: vars */
|
/* jshint unused: vars */
|
||||||
|
|
||||||
export default
|
export default
|
||||||
[ function() {
|
[ 'templateUrl',
|
||||||
|
function(templateUrl) {
|
||||||
return { restrict: 'E',
|
return { restrict: 'E',
|
||||||
templateUrl: '/static/js/system-tracking/fact-data-table/fact-data-table.partial.html',
|
templateUrl: templateUrl('system-tracking/fact-data-table/fact-data-table'),
|
||||||
scope:
|
scope:
|
||||||
{ leftHostname: '=',
|
{ leftHostname: '=',
|
||||||
rightHostname: '=',
|
rightHostname: '=',
|
||||||
|
|||||||
39
awx/ui/tests/unit/setup-browser.js
Normal file
39
awx/ui/tests/unit/setup-browser.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
var jsdom = require('jsdom').jsdom;
|
||||||
|
var document = jsdom('tower');
|
||||||
|
var window = document.parentWindow;
|
||||||
|
var mocha = require('mocha');
|
||||||
|
window.mocha = mocha;
|
||||||
|
window.beforeEach = beforeEach;
|
||||||
|
window.afterEach = afterEach;
|
||||||
|
|
||||||
|
global.document = document;
|
||||||
|
global.window = window;
|
||||||
|
|
||||||
|
require('angular/angular');
|
||||||
|
var jquery = require('jquery');
|
||||||
|
require('angular-mocks/angular-mocks');
|
||||||
|
|
||||||
|
var chai = require('chai');
|
||||||
|
var expect = chai.expect;
|
||||||
|
var sinonChai = require('sinon-chai');
|
||||||
|
var chaiAsPromised = require('chai-as-promised');
|
||||||
|
var sinon = require('sinon');
|
||||||
|
var chaiThings = require('chai-things');
|
||||||
|
|
||||||
|
chai.use(sinonChai);
|
||||||
|
chai.use(chaiAsPromised);
|
||||||
|
chai.use(chaiThings);
|
||||||
|
|
||||||
|
global.$ = window.$ = jquery;
|
||||||
|
global.angular = window.angular;
|
||||||
|
global.expect = chai.expect;
|
||||||
|
|
||||||
|
angular.module('templates', []);
|
||||||
|
require('../../templates');
|
||||||
|
|
||||||
|
var lodash = require('lodash');
|
||||||
|
global._ = lodash;
|
||||||
|
|
||||||
|
var LocalStorage = require('node-localstorage').LocalStorage;
|
||||||
|
global.localStorage = window.localStorage = new LocalStorage('./scratch');
|
||||||
|
|
||||||
Reference in New Issue
Block a user