mirror of
https://github.com/datahub-project/datahub.git
synced 2025-09-07 16:16:51 +00:00
Merge pull request #1252 from theseyi/refac-sources
refactors application controller and search service to ts. adds servi…
This commit is contained in:
commit
a597a7e185
@ -1,49 +0,0 @@
|
|||||||
import Controller from '@ember/controller';
|
|
||||||
import { get } from '@ember/object';
|
|
||||||
import { inject as service } from '@ember/service';
|
|
||||||
|
|
||||||
export default Controller.extend({
|
|
||||||
/**
|
|
||||||
* User session management service
|
|
||||||
* @type {Ember.Service}
|
|
||||||
*/
|
|
||||||
session: service(),
|
|
||||||
/**
|
|
||||||
* Injected global search service
|
|
||||||
* @type {Ember.Service}
|
|
||||||
*/
|
|
||||||
search: service(),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Looks up user names and properties from the partyEntities api
|
|
||||||
* @type {Ember.Service}
|
|
||||||
*/
|
|
||||||
ldapUsers: service('user-lookup'),
|
|
||||||
|
|
||||||
notifications: service(),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds the service for banners in order to trigger the application to render the banners when
|
|
||||||
* they are triggered
|
|
||||||
*/
|
|
||||||
banners: service(),
|
|
||||||
|
|
||||||
init() {
|
|
||||||
this._super(...arguments);
|
|
||||||
|
|
||||||
// Primes the cache for keywords and userEntitiesSource
|
|
||||||
get(this, 'ldapUsers.fetchUserNames')();
|
|
||||||
},
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
/**
|
|
||||||
* Invokes the search service api to transition to the
|
|
||||||
* search results page with the search string
|
|
||||||
* @param {String} [keyword] the search string to search for
|
|
||||||
* @param {String} [category] restrict search to results found here
|
|
||||||
*/
|
|
||||||
didSearch({ keyword, category }) {
|
|
||||||
get(this, 'search').showSearchResults({ keyword, category });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
60
wherehows-web/app/controllers/application.ts
Normal file
60
wherehows-web/app/controllers/application.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import Controller from '@ember/controller';
|
||||||
|
import { get } from '@ember/object';
|
||||||
|
import Session from 'ember-simple-auth/services/session';
|
||||||
|
import Search from 'wherehows-web/services/search';
|
||||||
|
import UserLookup from 'wherehows-web/services/user-lookup';
|
||||||
|
import Notifications from 'wherehows-web/services/notifications';
|
||||||
|
import BannerService from 'wherehows-web/services/banners';
|
||||||
|
import { action } from '@ember-decorators/object';
|
||||||
|
import { service } from '@ember-decorators/service';
|
||||||
|
|
||||||
|
export default class Application extends Controller {
|
||||||
|
/**
|
||||||
|
* User session management service
|
||||||
|
* @type {Session}
|
||||||
|
*/
|
||||||
|
@service session: Session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injected global search service
|
||||||
|
* @type {Search}
|
||||||
|
*/
|
||||||
|
@service search: Search;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Looks up user names and properties from the partyEntities api
|
||||||
|
* @type {UserLookup}
|
||||||
|
*/
|
||||||
|
@service('user-lookup') ldapUsers: UserLookup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* References the application notifications service
|
||||||
|
* @type {Notifications}
|
||||||
|
*/
|
||||||
|
@service notifications: Notifications;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the service for banners in order to trigger the application to render the banners when
|
||||||
|
* they are triggered
|
||||||
|
* @type {BannerService}
|
||||||
|
*/
|
||||||
|
@service('banners') banners: BannerService;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super(...arguments);
|
||||||
|
|
||||||
|
//@ts-ignore dot notation limitation with ts and ember object model
|
||||||
|
get(this, 'ldapUsers.fetchUserNames')();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invokes the search service api to transition to the
|
||||||
|
* search results page with the search parameters
|
||||||
|
* @param {String} [keyword] the search string to search for
|
||||||
|
* @param {String} [category] restrict search to results found here
|
||||||
|
*/
|
||||||
|
@action
|
||||||
|
didSearch({ keyword, category }: { keyword: string; category: string }) {
|
||||||
|
get(this, 'search').showSearchResults({ keyword, category });
|
||||||
|
}
|
||||||
|
}
|
@ -118,3 +118,10 @@ export default class BannerService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module '@ember/service' {
|
||||||
|
// eslint-disable-next-line typescript/interface-name-prefix
|
||||||
|
interface Registry {
|
||||||
|
banners: BannerService;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -397,3 +397,10 @@ export default class Notifications extends Service {
|
|||||||
this.dismissToast.call(this);
|
this.dismissToast.call(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module '@ember/service' {
|
||||||
|
// eslint-disable-next-line typescript/interface-name-prefix
|
||||||
|
interface Registry {
|
||||||
|
notifications: Notifications;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -3,14 +3,14 @@ import { getOwner } from '@ember/application';
|
|||||||
import { isBlank } from '@ember/utils';
|
import { isBlank } from '@ember/utils';
|
||||||
import { encode } from 'wherehows-web/utils/encode-decode-uri-component-with-space';
|
import { encode } from 'wherehows-web/utils/encode-decode-uri-component-with-space';
|
||||||
|
|
||||||
export default Service.extend({
|
export default class Search extends Service {
|
||||||
/**
|
/**
|
||||||
* Transition to the search route including search keyword as query parameter
|
* Transition to the search route including search keyword as query parameter
|
||||||
* @param {Object} args = {} a map of query parameters to values, including keyword
|
* @param {Object} args = {} a map of query parameters to values, including keyword
|
||||||
* @prop {String|*} args.keyword the string to search for
|
* @prop {String|*} args.keyword the string to search for
|
||||||
* @returns {void|Transition}
|
* @returns {void|Transition}
|
||||||
*/
|
*/
|
||||||
showSearchResults(args = {}) {
|
showSearchResults(args: { keyword: string; category: string }) {
|
||||||
let { keyword, category } = args;
|
let { keyword, category } = args;
|
||||||
|
|
||||||
// Transition to search route only if value is not null or void
|
// Transition to search route only if value is not null or void
|
||||||
@ -24,4 +24,11 @@ export default Service.extend({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
declare module '@ember/service' {
|
||||||
|
// eslint-disable-next-line typescript/interface-name-prefix
|
||||||
|
interface Registry {
|
||||||
|
search: Search;
|
||||||
|
}
|
||||||
|
}
|
@ -36,3 +36,10 @@ export default class UserLookup extends Service {
|
|||||||
userNamesResolver = ldapResolver;
|
userNamesResolver = ldapResolver;
|
||||||
fetchUserNames = getUserEntities;
|
fetchUserNames = getUserEntities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module '@ember/service' {
|
||||||
|
// eslint-disable-next-line typescript/interface-name-prefix
|
||||||
|
interface Registry {
|
||||||
|
'user-lookup': UserLookup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -49,6 +49,15 @@ declare module 'ember-simple-auth/services/session' {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module '@ember/service' {
|
||||||
|
import Session from 'ember-simple-auth/services/session';
|
||||||
|
|
||||||
|
// eslint-disable-next-line typescript/interface-name-prefix
|
||||||
|
interface Registry {
|
||||||
|
session: Session;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
declare module 'ember-inflector' {
|
declare module 'ember-inflector' {
|
||||||
const singularize: (arg: string) => string;
|
const singularize: (arg: string) => string;
|
||||||
const pluralize: (arg: string) => string;
|
const pluralize: (arg: string) => string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user