Commit 188aed1c authored by François Agneray's avatar François Agneray
Browse files

Add samp access accordion (result page)

parent cbf2b71c
......@@ -11,7 +11,7 @@ import { Action } from '@ngrx/store';
export const REGISTER = '[Samp] Register';
export const UNREGISTER = '[Samp] unregister';
export const BROADCAST = '[Samp] Broadcast';
export const BROADCAST_VOTABLE = '[Samp] Broadcast Votable';
/**
* @class
......@@ -37,16 +37,16 @@ export class RegisterAction implements Action {
/**
* @class
* @classdesc Broadcast action.
* @classdesc Broadcast votable action.
* @readonly
*/
export class BroadcastAction implements Action {
readonly type = BROADCAST;
export class BroadcastVotableAction implements Action {
readonly type = BROADCAST_VOTABLE;
constructor(public payload: {} = null) { }
constructor(public payload: string) { }
}
export type Actions
= RegisterAction
| UnregisterAction
| BroadcastAction;
| BroadcastVotableAction;
......@@ -32,4 +32,24 @@ export class SampEffects {
),
{ dispatch: false }
);
unregister$ = createEffect(() =>
this.actions$.pipe(
ofType(sampActions.UNREGISTER),
tap(_ => {
this.sampService.unregister();
})
),
{ dispatch: false }
);
broadcastVotable$ = createEffect(() =>
this.actions$.pipe(
ofType(sampActions.BROADCAST_VOTABLE),
tap((action: sampActions.BroadcastVotableAction) => {
this.sampService.broadcast('table.load.votable', action.payload)
})
),
{ dispatch: false }
);
}
......@@ -9,6 +9,8 @@
import { Injectable } from '@angular/core';
import { environment } from '../../../environments/environment';
declare var samp: any;
@Injectable()
......@@ -17,13 +19,31 @@ declare var samp: any;
* @classdesc Samp service.
*/
export class SampService {
connector = null;
private connector = null;
constructor() {
this.connector = new samp.Connector("pinger", {"samp.name": "Pinger"})
const baseUrl = window.location.protocol + "//" + window.location.host + environment.baseHref;
const meta = {
"samp.name": "ANIS",
"samp.description.text": "AstroNomical Information System",
"author.email": "cesamsi@lam.fr",
"author.affiliation": "CeSAM, Laboratoire d'Astrophysique de Marseille",
"home.page": "https://anis.lam.fr",
"samp.icon.url": baseUrl + "/assets/cesam_anis40.png"
};
this.connector = new samp.Connector("anis-client", meta)
}
register(): void {
this.connector.register();
}
unregister(): void {
this.connector.unregister();
}
register() {
this.connector.runWithConnection(connection => connection.notifyAll([new samp.Message("samp.app.ping", {})]));
broadcast(mtype: string, url: string): void {
const message = new samp.Message(mtype, {"url": encodeURI(url)});
this.connector.connection.notifyAll([message]);
}
}
......@@ -18,6 +18,7 @@ import { ReminderComponent } from './result/reminder.component';
import { UrlDisplaySectionComponent } from './result/url-display.component';
import { DatatableTabComponent } from './result/datatable-tab.component';
import { ConeSearchPlotTabComponent } from './result/cone-search-plot-tab.component';
import { SampComponent } from './result/samp.component';
export const dummiesComponents = [
ProgressBarComponent,
......@@ -39,5 +40,6 @@ export const dummiesComponents = [
ReminderComponent,
UrlDisplaySectionComponent,
DatatableTabComponent,
ConeSearchPlotTabComponent
ConeSearchPlotTabComponent,
SampComponent
];
......@@ -7,25 +7,22 @@
<div class="col-auto align-self-center">
<p>Download results just here:</p>
</div>
<div class="w-100 d-block d-xl-none"></div>
<div class="col">
<div class="row justify-content-around">
<div *ngIf="getConfigDownloadResultFormat('csv')" class="col-auto mb-2">
<a [href]="getUrl('csv')" class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_csv.svg'" title="Download results in CSV format"></span>
</a>
</div>
<div *ngIf="getConfigDownloadResultFormat('ascii')" class="col-auto mb-2">
<a [href]="getUrl('ascii')" target="_blank" class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_ascii.svg'" title="Download results in ASCII format"></span>
</a>
</div>
<div *ngIf="getConfigDownloadResultFormat('vo')" class="col-auto mb-2">
<a [href]="getUrl('votable')" target="_blank" class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_vo.svg'" title="Download results in VO format"></span>
</a>
</div>
</div>
<a *ngIf="getConfigDownloadResultFormat('csv')" [href]="getUrl('csv')" class="btn btn-outline-primary" title="Download results in CSV format">
<i class="fas fa-file-csv"></i> Download csv
</a>
&nbsp;
<a *ngIf="getConfigDownloadResultFormat('ascii')" [href]="getUrl('ascii')" target="_blank" class="btn btn-outline-primary" title="Download results in ASCII format">
<i class="fas fa-file"></i> Download ascii
</a>
&nbsp;
<a *ngIf="getConfigDownloadResultFormat('vo')" [href]="getUrl('votable')" target="_blank" class="btn btn-outline-primary" title="Download results in VO format">
<i class="fas fa-file"></i> Download votable
</a>
&nbsp;
<button *ngIf="getConfigDownloadResultFormat('vo')" (click)="broadcastVotable()" class="btn btn-outline-primary" title="Broadcast samp votable">
<i class="fas fa-broadcast-tower"></i> Broadcast votable
</button>
</div>
</div>
<hr class="my-4">
......@@ -33,15 +30,10 @@
<div class="col-auto align-self-center">
<p>Download archive files just here:</p>
</div>
<div class="w-100 d-block d-xl-none"></div>
<div class="col">
<div class="row justify-content-around">
<div class="col-auto mb-2">
<a [href]="getUrlArchive()" class="btn btn-lg btn-block dl-btn">
<span [inlineSVG]="'assets/logo_stamp.svg'" title="Download results in CSV format"></span>
</a>
</div>
</div>
<a [href]="getUrlArchive()" class="btn btn-outline-primary" title="Download an archive with all files">
<i class="fas fa-archive"></i> Download files archive
</a>
</div>
</div>
</div>
\ No newline at end of file
......@@ -35,6 +35,7 @@ export class DownloadComponent implements OnInit {
@Input() criteriaList: Criterion[];
@Input() outputList: number[];
@Output() getDataLength: EventEmitter<null> = new EventEmitter();
@Output() broadcast: EventEmitter<string> = new EventEmitter();
ngOnInit() {
this.getDataLength.emit();
......@@ -106,4 +107,8 @@ export class DownloadComponent implements OnInit {
}
return query;
}
broadcastVotable(): void {
this.broadcast.emit(this.getUrl('votable'));
}
}
<accordion [isAnimated]="true">
<accordion-group #ag [isOpen]="false" [panelClass]="'custom-accordion'" class="my-2">
<button class="btn btn-link btn-block clearfix" accordion-heading>
<span class="pull-left float-left">
<span [style.color]="getColor()">
<i class="fas fa-circle"></i>
</span> SAMP access
&nbsp;
<span *ngIf="ag.isOpen">
<span class="fas fa-chevron-up"></span>
</span>
<span *ngIf="!ag.isOpen">
<span class="fas fa-chevron-down"></span>
</span>
</span>
</button>
<div>
<div class="row">
<p *ngIf="!sampRegistered" class="lead">
You are not connected to a SAMP-hub
</p>
<p *ngIf="sampRegistered" class="lead">
You are connected to a SAMP-hub
</p>
</div>
<div class="row">
<button *ngIf="!sampRegistered" (click)="sampRegister.emit()" class="btn btn-outline-primary">Try to register</button>
<button *ngIf="sampRegistered" (click)="sampUnregister.emit()" class="btn btn-outline-primary">Unregister</button>
</div>
</div>
</accordion-group>
</accordion>
\ No newline at end of file
/**
* This file is part of Anis Client.
*
* @copyright Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Component, Input, ChangeDetectionStrategy, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'app-samp',
templateUrl: 'samp.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
/**
* @class
* @classdesc Samp component.
*/
export class SampComponent {
@Input() sampRegistered: boolean;
@Output() sampRegister: EventEmitter<{}> = new EventEmitter();
@Output() sampUnregister: EventEmitter<{}> = new EventEmitter();
getColor(): string {
if (this.sampRegistered) {
return 'green';
} else {
return 'red';
}
}
}
......@@ -4,10 +4,6 @@
<span class="sr-only">Loading...</span>
</div>
<div *ngIf="(datasetSearchMetaIsLoaded | async) && (attributeListIsLoaded | async)" class="row mt-4">
<button (click)="sampRegister()" class="btn btn-outline-primary">Samp register</button>
</div>
<div *ngIf="(datasetSearchMetaIsLoaded | async) && (attributeListIsLoaded | async)" class="row mt-4">
<div class="col-12">
<app-result-download
......@@ -19,7 +15,8 @@
[coneSearch]="coneSearch | async"
[criteriaList]="criteriaList | async"
[outputList]="outputList | async"
(getDataLength)="getDataLength()">
(getDataLength)="getDataLength()"
(broadcast)="broadcastVotable($event)">
</app-result-download>
<app-reminder
[datasetAttributeList]="attributeList | async"
......@@ -32,6 +29,11 @@
[categoryList]="categoryList | async"
[outputList]="outputList | async">
</app-reminder>
<app-samp
[sampRegistered]="sampRegistered | async"
(sampRegister)="sampRegister()"
(sampUnregister)="sampUnregister()">
</app-samp>
<app-result-url-display
[datasetList]="datasetList | async"
[dataLengthIsLoaded]="dataLengthIsLoaded | async"
......
......@@ -13,6 +13,7 @@ import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import * as sampActions from '../../samp/store/samp.action';
import * as sampSelector from '../../samp/store/samp.selector';
import * as fromSearch from '../store/search.reducer';
import * as searchActions from '../store/search.action';
import * as searchSelector from '../store/search.selector';
......@@ -71,6 +72,7 @@ export class ResultComponent implements OnInit, OnDestroy {
public processWip: Observable<boolean>;
public processDone: Observable<boolean>;
public processId: Observable<string>;
public sampRegistered: Observable<boolean>;
constructor(private store: Store<StoreState>, private scrollTopService: ScrollTopService) {
this.datasetSearchMetaIsLoading = store.select(metamodelSelector.getDatasetSearchMetaIsLoading);
......@@ -93,6 +95,7 @@ export class ResultComponent implements OnInit, OnDestroy {
this.processWip = this.store.select(searchSelector.getProcessWip);
this.processDone = this.store.select(searchSelector.getProcessDone);
this.processId = this.store.select(searchSelector.getProcessId);
this.sampRegistered = this.store.select(sampSelector.getRegistered);
}
ngOnInit() {
......@@ -116,6 +119,14 @@ export class ResultComponent implements OnInit, OnDestroy {
this.store.dispatch(new sampActions.RegisterAction());
}
sampUnregister() {
this.store.dispatch(new sampActions.UnregisterAction());
}
broadcastVotable(url: string) {
this.store.dispatch(new sampActions.BroadcastVotableAction(url));
}
/**
* Dispatches action to retrieve result number.
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment