removed unnecessary factory classes, simplified existing services
This commit is contained in:
parent
2a59014f0b
commit
64a4b68216
15 changed files with 69 additions and 158 deletions
|
@ -13,7 +13,7 @@ angular.module('quay').directive('buildLogsView', function () {
|
|||
'useTimestamps': '=useTimestamps',
|
||||
'buildUpdated': '&buildUpdated'
|
||||
},
|
||||
controller: function($scope, $element, $interval, $sanitize, ansi2html, ViewArrayFactory,
|
||||
controller: function($scope, $element, $interval, $sanitize, ansi2html, ViewArray,
|
||||
AngularPollChannel, ApiService, Restangular, UtilService) {
|
||||
|
||||
var result = $element.find('#copyButton').clipboardCopy();
|
||||
|
@ -53,7 +53,7 @@ angular.module('quay').directive('buildLogsView', function () {
|
|||
var entry = logs[i];
|
||||
var type = entry['type'] || 'entry';
|
||||
if (type == 'command' || type == 'phase' || type == 'error') {
|
||||
entry['logs'] = ViewArrayFactory.create();
|
||||
entry['logs'] = ViewArray.create();
|
||||
entry['index'] = $scope.logStartIndex + i;
|
||||
|
||||
$scope.logEntries.push(entry);
|
||||
|
|
|
@ -13,7 +13,7 @@ angular.module('quay').directive('imageFeatureView', function () {
|
|||
'image': '=image',
|
||||
'isEnabled': '=isEnabled'
|
||||
},
|
||||
controller: function($scope, $element, Config, ApiService, VulnerabilityService, ViewArrayFactory, ImageMetadataService, TableService) {
|
||||
controller: function($scope, $element, Config, ApiService, VulnerabilityService, ViewArray, ImageMetadataService, TableService) {
|
||||
$scope.options = {
|
||||
'filter': null,
|
||||
'predicate': 'fixableScore',
|
||||
|
|
|
@ -13,7 +13,7 @@ angular.module('quay').directive('imageVulnerabilityView', function () {
|
|||
'image': '=image',
|
||||
'isEnabled': '=isEnabled'
|
||||
},
|
||||
controller: function($scope, $element, Config, ApiService, VulnerabilityService, ViewArrayFactory, ImageMetadataService, TableService) {
|
||||
controller: function($scope, $element, Config, ApiService, VulnerabilityService, ViewArray, ImageMetadataService, TableService) {
|
||||
$scope.options = {
|
||||
'filter': null,
|
||||
'fixableVulns': false,
|
||||
|
|
|
@ -2,8 +2,7 @@ import * as angular from 'angular';
|
|||
import { quayConfig } from './quay.config';
|
||||
import quayPages from './quay-pages.module';
|
||||
import quayRun from './quay.run';
|
||||
import { ViewArrayFactory } from './services/view-array/view-array.factory';
|
||||
import RouteBuilderFactory from './services/route-builder/route-builder.factory';
|
||||
import { ViewArrayImpl } from './services/view-array/view-array.impl';
|
||||
import NAME_PATTERNS from './constants/name-patterns.constant';
|
||||
import { routeConfig } from './quay.routes';
|
||||
import { CONFIG } from './constants/quay-config.constant';
|
||||
|
@ -51,7 +50,6 @@ export default angular
|
|||
.config(routeConfig)
|
||||
.constant('NAME_PATTERNS', NAME_PATTERNS)
|
||||
.constant('CONFIG', CONFIG)
|
||||
.service('RouteBuilderFactory', RouteBuilderFactory)
|
||||
.service('ViewArrayFactory', ViewArrayFactory)
|
||||
.service('ViewArray', ViewArrayImpl)
|
||||
.run(quayRun)
|
||||
.name;
|
|
@ -1,18 +1,16 @@
|
|||
import RouteBuilderFactory from './services/route-builder/route-builder.factory';
|
||||
import { RouteBuilderImpl } from './services/route-builder/route-builder.service.impl';
|
||||
import { RouteBuilder } from './services/route-builder/route-builder.service';
|
||||
import pages from './constants/pages.constant';
|
||||
|
||||
|
||||
routeConfig.$inject = [
|
||||
'pages',
|
||||
'RouteBuilderFactoryProvider',
|
||||
'$routeProvider',
|
||||
'$locationProvider',
|
||||
];
|
||||
|
||||
export function routeConfig(
|
||||
pages: any,
|
||||
RouteBuilderFactoryProvider: any,
|
||||
$routeProvider: ng.route.IRouteProvider,
|
||||
$locationProvider: ng.ILocationProvider) {
|
||||
$locationProvider.html5Mode(true);
|
||||
|
@ -22,15 +20,7 @@ export function routeConfig(
|
|||
// index rule to make sure that deep links directly deep into the app continue to work.
|
||||
// WARNING WARNING WARNING
|
||||
|
||||
var layoutProfile: string = 'layout';
|
||||
|
||||
var routeBuilder: RouteBuilder = RouteBuilderFactoryProvider.$get().create($routeProvider, pages, [
|
||||
// Start with the old pages (if we asked for it).
|
||||
{id: 'old-layout', templatePath: '/static/partials/'},
|
||||
|
||||
// Fallback back combined new/existing pages.
|
||||
{id: 'layout', templatePath: '/static/partials/'}
|
||||
], layoutProfile);
|
||||
var routeBuilder: RouteBuilder = new RouteBuilderImpl($routeProvider, pages);
|
||||
|
||||
if ((<any>window).__features.SUPER_USERS) {
|
||||
// QE Management
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
import RouteBuilderFactory from './route-builder.factory';
|
||||
import { RouteBuilder } from "static/js/services/route-builder/route-builder.service";
|
||||
|
||||
|
||||
describe("Factory: RouteBuilderFactory", () => {
|
||||
var routeBuilderFactory: RouteBuilderFactory;
|
||||
var routeProviderMock;
|
||||
var pagesMock;
|
||||
var profiles;
|
||||
var currentProfile;
|
||||
|
||||
beforeEach(() => {
|
||||
profiles = [
|
||||
{id: 'old-layout', templatePath: '/static/partials/'},
|
||||
{id: 'layout', templatePath: '/static/partials/'}
|
||||
];
|
||||
currentProfile = 'layout';
|
||||
routeProviderMock = jasmine.createSpyObj('routeProvider', ['otherwise', 'when']);
|
||||
pagesMock = jasmine.createSpyObj('pagesMock', ['get', 'create']);
|
||||
routeBuilderFactory = new RouteBuilderFactory();
|
||||
});
|
||||
|
||||
describe("constructor", () => {
|
||||
|
||||
});
|
||||
|
||||
describe("create", () => {
|
||||
|
||||
it("returns a RouteBuilder instance", () => {
|
||||
var routeBuilder: RouteBuilder = routeBuilderFactory.create(routeProviderMock, pagesMock, profiles, currentProfile);
|
||||
|
||||
expect(routeBuilder).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,14 +0,0 @@
|
|||
import { RouteBuilder } from './route-builder.service';
|
||||
import { RouteBuilderImpl } from './route-builder.service.impl';
|
||||
|
||||
|
||||
export default class RouteBuilderFactory {
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
public create(routeProvider, pages, profiles, currentProfile): RouteBuilder {
|
||||
return new RouteBuilderImpl(routeProvider, pages, profiles, currentProfile);
|
||||
}
|
||||
}
|
|
@ -1,18 +1,20 @@
|
|||
import { RouteBuilder } from './route-builder.service';
|
||||
|
||||
|
||||
export function routeBuilderFactory() {
|
||||
return (routeProvider, pages, profiles, currentProfile): RouteBuilder => {
|
||||
return new RouteBuilderImpl(routeProvider, pages, profiles, currentProfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class RouteBuilderImpl implements RouteBuilder {
|
||||
|
||||
constructor(private routeProvider, private pages, public profiles, currentProfile) {
|
||||
public currentProfile: string = 'layout';
|
||||
public profiles: any[] = [
|
||||
// Start with the old pages (if we asked for it).
|
||||
{id: 'old-layout', templatePath: '/static/partials/'},
|
||||
// Fallback back combined new/existing pages.
|
||||
{id: 'layout', templatePath: '/static/partials/'}
|
||||
];
|
||||
|
||||
|
||||
constructor(private routeProvider: ng.route.IRouteProvider, private pages: any) {
|
||||
for (let i = 0; i < this.profiles.length; ++i) {
|
||||
if (this.profiles[i].id == currentProfile) {
|
||||
if (this.profiles[i].id == this.currentProfile) {
|
||||
this.profiles = this.profiles.slice(i);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -2,17 +2,15 @@ import { RouteBuilderImpl } from './route-builder.service.impl';
|
|||
|
||||
|
||||
describe("Service: RouteBuilderImpl", () => {
|
||||
var routeProviderMock;
|
||||
var pagesMock;
|
||||
var profiles;
|
||||
var currentProfile;
|
||||
var routeProviderMock: any;
|
||||
var pagesMock: any;
|
||||
var profiles: any[];
|
||||
|
||||
beforeEach((() => {
|
||||
profiles = [
|
||||
{id: 'old-layout', templatePath: '/static/partials/'},
|
||||
{id: 'layout', templatePath: '/static/partials/'}
|
||||
];
|
||||
currentProfile = 'layout';
|
||||
routeProviderMock = jasmine.createSpyObj('routeProvider', ['otherwise', 'when']);
|
||||
pagesMock = jasmine.createSpyObj('pagesMock', ['get', 'create']);
|
||||
}));
|
||||
|
@ -20,29 +18,37 @@ describe("Service: RouteBuilderImpl", () => {
|
|||
describe("constructor", () => {
|
||||
|
||||
it("returns a RouteBuilder object", () => {
|
||||
var routeBuilder = new RouteBuilderImpl(routeProviderMock, pagesMock, profiles, currentProfile);
|
||||
var routeBuilder: RouteBuilderImpl = new RouteBuilderImpl(routeProviderMock, pagesMock);
|
||||
|
||||
expect(routeBuilder).toBeDefined();
|
||||
});
|
||||
|
||||
it("sets 'profiles' to all given profiles if given current profile does not match any of the given profiles' id", () => {
|
||||
var routeBuilder = new RouteBuilderImpl(routeProviderMock, pagesMock, profiles, 'fake-profile');
|
||||
it("initializes current profile to 'layout'", () => {
|
||||
var routeBuilder: RouteBuilderImpl = new RouteBuilderImpl(routeProviderMock, pagesMock);
|
||||
|
||||
expect(routeBuilder.profiles).toEqual(profiles);
|
||||
expect(routeBuilder.currentProfile).toEqual('layout');
|
||||
});
|
||||
|
||||
it("initializes available profiles", () => {
|
||||
var routeBuilder: RouteBuilderImpl = new RouteBuilderImpl(routeProviderMock, pagesMock);
|
||||
var matchingRoutes: any[] = routeBuilder.profiles.filter((profile) => {
|
||||
return profiles.indexOf(profile) == -1;
|
||||
});
|
||||
expect(matchingRoutes).toEqual(routeBuilder.profiles);
|
||||
});
|
||||
|
||||
it("sets 'profiles' to the first given profile with id matching given current profile", () => {
|
||||
var routeBuilder = new RouteBuilderImpl(routeProviderMock, pagesMock, profiles, currentProfile);
|
||||
var routeBuilder: RouteBuilderImpl = new RouteBuilderImpl(routeProviderMock, pagesMock);
|
||||
|
||||
expect(routeBuilder.profiles).toEqual([profiles[1]]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("otherwise", () => {
|
||||
var routeBuilder;
|
||||
var routeBuilder: RouteBuilderImpl;
|
||||
|
||||
beforeEach(() => {
|
||||
routeBuilder = new RouteBuilderImpl(routeProviderMock, pagesMock, profiles, currentProfile);
|
||||
routeBuilder = new RouteBuilderImpl(routeProviderMock, pagesMock);
|
||||
});
|
||||
|
||||
it("calls routeProvider to set fallback route with given options", () => {
|
||||
|
@ -54,10 +60,10 @@ describe("Service: RouteBuilderImpl", () => {
|
|||
});
|
||||
|
||||
describe("route", () => {
|
||||
var routeBuilder;
|
||||
var path;
|
||||
var pagename;
|
||||
var page;
|
||||
var routeBuilder: RouteBuilderImpl;
|
||||
var path: string;
|
||||
var pagename: string;
|
||||
var page: any;
|
||||
|
||||
beforeEach(() => {
|
||||
path = '/repository/:namespace/:name';
|
||||
|
@ -68,7 +74,7 @@ describe("Service: RouteBuilderImpl", () => {
|
|||
controller: jasmine.createSpy('pageController'),
|
||||
flags: {},
|
||||
};
|
||||
routeBuilder = new RouteBuilderImpl(routeProviderMock, pagesMock, profiles, currentProfile);
|
||||
routeBuilder = new RouteBuilderImpl(routeProviderMock, pagesMock);
|
||||
});
|
||||
|
||||
it("calls pages with given pagename and 'profiles' to get matching page and profile pair", () => {
|
||||
|
@ -91,7 +97,7 @@ describe("Service: RouteBuilderImpl", () => {
|
|||
|
||||
it("calls routeProvider to set route for given path and options", () => {
|
||||
pagesMock.get.and.returnValue([profiles[1], page]);
|
||||
var expectedOptions = {
|
||||
var expectedOptions: any = {
|
||||
templateUrl: profiles[1].templatePath + page.templateName,
|
||||
reloadOnSearch: false,
|
||||
controller: page.controller,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Service which provides helper methods for constructing and managing tabular data.
|
||||
*/
|
||||
angular.module('quay').factory('TableService', ['ViewArrayFactory', function(ViewArrayFactory) {
|
||||
angular.module('quay').factory('TableService', ['ViewArray', function(ViewArray) {
|
||||
var tableService = {};
|
||||
|
||||
tableService.tablePredicateClass = function(name, predicate, reverse) {
|
||||
|
@ -31,7 +31,7 @@ angular.module('quay').factory('TableService', ['ViewArrayFactory', function(Vie
|
|||
};
|
||||
|
||||
tableService.buildOrderedItems = function(items, options, filterFields, numericFields, opt_extrafilter) {
|
||||
var orderedItems = ViewArrayFactory.create();
|
||||
var orderedItems = ViewArray.create();
|
||||
|
||||
items.forEach(function(item) {
|
||||
var filter = options.filter;
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
import { ViewArrayFactory } from './view-array.factory';
|
||||
import { ViewArray } from './view-array';
|
||||
|
||||
|
||||
describe("Factory: ViewArrayFactory", () => {
|
||||
var viewArrayFactory: ViewArrayFactory;
|
||||
var $intervalMock: any;
|
||||
|
||||
beforeEach(() => {
|
||||
$intervalMock = jasmine.createSpy('$intervalSpy');
|
||||
$intervalMock.cancel = jasmine.createSpy('cancelSpy');
|
||||
viewArrayFactory = new ViewArrayFactory($intervalMock)
|
||||
});
|
||||
|
||||
describe("constructor", () => {
|
||||
|
||||
});
|
||||
|
||||
describe("create", () => {
|
||||
|
||||
it("returns a ViewArray object", () => {
|
||||
var viewArray: ViewArray = viewArrayFactory.create();
|
||||
|
||||
expect(viewArray).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,29 +0,0 @@
|
|||
import { ViewArray } from './view-array';
|
||||
import { ViewArrayImpl } from './view-array.impl';
|
||||
import { Inject } from '../../decorators/inject/inject.decorator';
|
||||
|
||||
|
||||
/**
|
||||
* Factory for creating ViewArray instances.
|
||||
*/
|
||||
export class ViewArrayFactory {
|
||||
|
||||
private ADDITIONAL_ENTRIES: number = 20;
|
||||
|
||||
/**
|
||||
* @param $interval Angular $interval service.
|
||||
* @return viewArrayFactory A factory for creating ViewArray objects.
|
||||
*/
|
||||
constructor(@Inject('$interval') private $interval: ng.IIntervalService) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ViewArray object.
|
||||
* @return viewArray New ViewArrayImpl instance.
|
||||
*/
|
||||
public create(): ViewArray {
|
||||
return new ViewArrayImpl(this.$interval, this.ADDITIONAL_ENTRIES);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,14 +4,12 @@ import { ViewArrayImpl } from './view-array.impl';
|
|||
describe("ViewArrayImplImpl", () => {
|
||||
var viewArrayImpl: ViewArrayImpl;
|
||||
var $intervalMock: any;
|
||||
var additionalCount: number;
|
||||
|
||||
beforeEach(() => {
|
||||
$intervalMock = jasmine.createSpy('$intervalSpy');
|
||||
$intervalMock.and.returnValue({});
|
||||
$intervalMock.cancel = jasmine.createSpy('cancelSpy');
|
||||
additionalCount = 20;
|
||||
viewArrayImpl = new ViewArrayImpl($intervalMock, additionalCount);
|
||||
viewArrayImpl = new ViewArrayImpl($intervalMock);
|
||||
});
|
||||
|
||||
|
||||
|
@ -137,4 +135,13 @@ describe("ViewArrayImplImpl", () => {
|
|||
expect($intervalMock.cancel).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("create", () => {
|
||||
|
||||
it("returns a new ViewArrayImpl instance", () => {
|
||||
var newViewArrayImpl: ViewArrayImpl = viewArrayImpl.create();
|
||||
|
||||
expect(newViewArrayImpl).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,4 +1,5 @@
|
|||
import { ViewArray } from './view-array';
|
||||
import { Inject } from '../../decorators/inject/inject.decorator';
|
||||
|
||||
|
||||
export class ViewArrayImpl implements ViewArray {
|
||||
|
@ -10,8 +11,9 @@ export class ViewArrayImpl implements ViewArray {
|
|||
public hasHiddenEntries: boolean;
|
||||
private timerRef: any;
|
||||
private currentIndex: number;
|
||||
private additionalCount: number = 20;
|
||||
|
||||
constructor(private interval: any, private additionalCount: number) {
|
||||
constructor(@Inject('$interval') private interval: any) {
|
||||
this.isVisible = false;
|
||||
this.visibleEntries = null;
|
||||
this.hasEntries = false;
|
||||
|
@ -57,6 +59,10 @@ export class ViewArrayImpl implements ViewArray {
|
|||
}
|
||||
}
|
||||
|
||||
public create(): ViewArrayImpl {
|
||||
return new ViewArrayImpl(this.interval);
|
||||
}
|
||||
|
||||
private showAdditionalEntries(): void {
|
||||
var i: number = 0;
|
||||
for (i = this.currentIndex; i < (this.currentIndex + this.additionalCount) && i < this.entries.length; ++i) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ViewArrayImpl } from "static/js/services/view-array/view-array.impl";
|
||||
/**
|
||||
* Specialized wrapper around array which provides a toggle() method for viewing the contents of the
|
||||
* array in a manner that is asynchronously filled in over a short time period. This prevents long
|
||||
|
@ -59,4 +60,10 @@ export abstract class ViewArray {
|
|||
* @param newState True/False if the contents are visible.
|
||||
*/
|
||||
public abstract setVisible(newState: boolean): void;
|
||||
|
||||
/**
|
||||
* Factory function to create a new ViewArray.
|
||||
* @return viewArray New ViewArray instance.
|
||||
*/
|
||||
public abstract create(): ViewArrayImpl;
|
||||
}
|
Reference in a new issue