Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 35 additions & 36 deletions angular/src/app/adv-search/adv-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft

super();

this.renderer.listen('window', 'click',(e:Event)=>{
this.renderer.listen('window', 'click',(e:Event)=>{
// If user clicks on the dropdown button, display the action popup list
//otherwise hide it.
if(e.target['name'] == 'dropdownButton')
Expand All @@ -87,6 +87,11 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft
this.showDropdown = false;
})

this.searchFieldsListService.watchFields().subscribe((fields) => {
this.fields = fields as SelectItem[];
this.doSearch();
})

this.fields = [];
this.mobHeight = (window.innerHeight);
this.mobWidth = (window.innerWidth);
Expand All @@ -100,32 +105,26 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft
ngOnInit() {
var i = 0;

this.searchFieldsListService.getSearchFields().subscribe(
(fields) => {
this.fields = (fields as SelectItem[]);
this.queries = this.searchQueryService.getQueries();
this.currentQueryInfo = this.searchQueryService.getCurrentQueryInfo();
this.currentQuery = this.currentQueryInfo.query;
this.dataChanged = this.currentQueryInfo.dataChanged; //Restore status
this.currentQueryIndex = this.currentQueryInfo.queryIndex;
if(!this.currentQuery) this.currentQuery = new SDPQuery();
if(this.currentQuery.queryRows.length == 0) this.currentQuery.queryRows.push(new QueryRow());

this.searchValue = this.searchQueryService.buildSearchString(this.currentQuery);
// Update search box in the top search panel
this.searchService.setQueryValue(this.searchValue, '', '');
},
(err) => {
this.errorMessage = <any>err;
}
);

this.searchQueryService.watchQueries().subscribe(value => {
if(value)
this.queries = value as SDPQuery[];
});
}

doSearch() {
this.queries = this.searchQueryService.getQueries();
this.currentQueryInfo = this.searchQueryService.getCurrentQueryInfo();
this.currentQuery = this.currentQueryInfo.query;
this.dataChanged = this.currentQueryInfo.dataChanged; //Restore status
this.currentQueryIndex = this.currentQueryInfo.queryIndex;
if(!this.currentQuery) this.currentQuery = new SDPQuery();
if(this.currentQuery.queryRows.length == 0) this.currentQuery.queryRows.push(new QueryRow());

this.searchValue = this.searchQueryService.buildSearchString(this.currentQuery);
// Update search box in the top search panel
this.searchService.setQueryValue(this.searchValue, '', '');
}

/**
* Following functions detect screen size
*/
Expand Down Expand Up @@ -175,7 +174,7 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft
if(!_.isEmpty(prevName) && newName == prevName){
return;
}

this.queryNameValidateErrorMsg = "";
this.queryNameValidateError = false;

Expand All @@ -185,7 +184,7 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft
} else {
if(this.queries.length > 0){
let prevQueryName: string = "";

if(!this.searchQueryService.queryNameValidation(newName, prevQueryName)){
this.queryNameValidateErrorMsg = "Existing query will be overwritten if continue!";
this.queryNameValidateError = true;
Expand Down Expand Up @@ -357,17 +356,17 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft
}

/**
* Save query
* Save query
* 1. Filter current query from the list
* 2. Add the new query to the list
*/
confirmSaveAdvSearchQuery(event, overlaypanel: OverlayPanel) {
this.tempName = this.currentQuery.queryName;
overlaypanel.toggle(event);

setTimeout(()=>{
setTimeout(()=>{
this.queryName.nativeElement.focus();
},0);
},0);
}

saveAdvQuery(inputQuery: SDPQuery, overlaypanel: OverlayPanel, newName? : string){
Expand Down Expand Up @@ -461,9 +460,9 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft
this.searchService.setQueryValue(lQueryValue, '', '');
this.searchService.search(lQueryValue);
}

/**
* Set the current query, build the search string.
* Set the current query, build the search string.
* @param index - the index number of the current query
*/
setCurrentQuery(query: SDPQuery, event?: any, index: number = -1){
Expand All @@ -479,19 +478,19 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft
}

setCurrentQueryNoAsk(query: SDPQuery, index: number = -1){
this.currentQuery = JSON.parse(JSON.stringify(query));
this.currentQuery = JSON.parse(JSON.stringify(query));
this.currentQueryIndex = index;
this.dataChanged = false;
this.saveCurrentQueryInfo();

this.searchValue = this.searchQueryService.buildSearchString(this.currentQuery);
// Update search box in the top search panel
this.searchService.setQueryValue(this.searchValue, '', '');
this.searchService.setQueryValue(this.searchValue, '', '');
}

/**
* When field type dropdown changed, if not edit/add mode, set to edit mode.
* @param event
* @param event
*/
onDataChange() {
this.dataChanged = true;
Expand All @@ -502,7 +501,7 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft

onFieldTypeChange(row: QueryRow){
let field = this.fields.filter(field => field.label == row.fieldType);
if(field != null && field.length > 0)
if(field != null && field.length > 0)
row.fieldValue = field[0].value;

if(!_.isEmpty(row.fieldText)){
Expand Down Expand Up @@ -552,7 +551,7 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft

/**
* Return placeholder text based on query row status
* @param queryRow
* @param queryRow
*/
getFieldTextPlacehoder(queryRow: QueryRow){
if(!_.isEmpty(queryRow.fieldValue)){
Expand All @@ -565,8 +564,8 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft
/**
* Rename a query
* @param query - query to be renamed
* @param event -
* @param index - query index in quert list
* @param event -
* @param index - query index in quert list
*/
renameQuery(query: SDPQuery, event: any, index: number){
this.tobeRenamedQuery = query;
Expand All @@ -575,7 +574,7 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft
}

saveRenamedQuery(queryName: string, op: OverlayPanel){
this.tobeRenamedQuery.queryName=queryName;
this.tobeRenamedQuery.queryName=queryName;
this.searchQueryService.saveQueries(this.queries);
op.hide();
}
Expand Down
30 changes: 19 additions & 11 deletions angular/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { concat } from 'rxjs';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, NavigationEnd, Router, RouterState } from '@angular/router';
import { DOCUMENT } from '@angular/common';
import { SearchfieldsListService } from './shared';

enum MenuOrientation {
STATIC,
Expand Down Expand Up @@ -74,15 +75,22 @@ export class AppComponent implements AfterViewInit {
private gaService: GoogleAnalyticsService,
public router: Router,
private titleService: Title,
public searchFieldsListService: SearchfieldsListService,
@Inject(DOCUMENT) private document: Document) {

}

ngAfterViewInit() {
this.layoutContainer = <HTMLDivElement>this.layourContainerViewChild.nativeElement;
}

ngOnInit() {

//Load fields so it's avialble for search result page and search panel
this.searchFieldsListService.getSearchFields().subscribe((fields) => {
// Do nothing. The service set the BehaviorSubject.
});

this.appConfig.getConfig().subscribe(
(conf) => {
this.gaCode = conf.GACODE;
Expand All @@ -92,12 +100,12 @@ export class AppComponent implements AfterViewInit {

/**
* Added Google Analytics service to html
*
* Google Analytics service code was removed from index.html because
* it's not yet calling config service. While adding Google Analytics
* service code here, the header menu and footer are all available
* at this time so we don't need to msnuslly track user events in header
* menu and footer links. But we still need to track user event of the
*
* Google Analytics service code was removed from index.html because
* it's not yet calling config service. While adding Google Analytics
* service code here, the header menu and footer are all available
* at this time so we don't need to msnuslly track user events in header
* menu and footer links. But we still need to track user event of the
* dynamic content.
*/
this.gaService.appendGaTrackingCode(this.gaCode, this.ga4Code, this.hostName);
Expand All @@ -116,23 +124,23 @@ export class AppComponent implements AfterViewInit {
if (event instanceof NavigationEnd) {
const title = this.getTitle(this.router.routerState, this.router.routerState.root).join('-') || 'NIST Data Repository Page';
this.titleService.setTitle(title);

gtag('event', 'page_view', {
page_title: title,
page_path: event.urlAfterRedirects,
page_location: this.document.location.href,
cookie_domain: this.hostName,
cookie_domain: this.hostName,
cookie_flags: 'SameSite=None;Secure'
})
}
});
}

/**
* Get page title if any
* @param state router state
* @param parent Activated route
* @returns
* @returns
*/
getTitle(state: RouterState, parent: ActivatedRoute): string[] {
const data = [];
Expand Down
3 changes: 3 additions & 0 deletions angular/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { MegaMenuModule } from "primeng/megamenu";
import { TagModule } from "primeng/tag";
import { BreadcrumbModule } from "primeng/breadcrumb";
import { ImageModule } from "primeng/image"
import { SearchfieldsListService, TaxonomyListService } from "./shared";
/**
* Initialize the configs for backend services
*/
Expand Down Expand Up @@ -109,6 +110,8 @@ enableProdMode();
GoogleAnalyticsService,
GoogleAnalyticsServiceMock,
NotificationService,
SearchfieldsListService,
TaxonomyListService,
{
provide: APP_INITIALIZER,
useFactory: appInitializerFn,
Expand Down
12 changes: 4 additions & 8 deletions angular/src/app/search-panel/search-panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,10 @@ export class SearchPanelComponent implements OnInit {
this.changeState(showExample);
});

this.searchFieldsListService.getSearchFields().subscribe(
(fields) => {
this.fields = fields as SelectItem[];
},
(err) => {
console.log("Error getting fields.", err);
}
);
//The app.component load the fields in ngOnInit and be catched here:
this.searchFieldsListService.watchFields().subscribe((fields) => {
this.fields = fields as SelectItem[];
})

// Init search box size and breadcrumb position
this.onWindowResize();
Expand Down
4 changes: 3 additions & 1 deletion angular/src/app/search/filters/filters.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ describe('FiltersComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(FiltersComponent);
component = fixture.componentInstance;
component.fields = [];
component.searchValue = "";
fixture.detectChanges();
});

Expand Down Expand Up @@ -70,4 +72,4 @@ describe('FiltersComponent', () => {
expect(component.authors[0]).toEqual("Michael Winchester");
expect(component.authors[5]).toEqual("James Alexander Liddle");
});
})
})
Loading
Loading