Project

General

Profile

1
import {Injectable} from '@angular/core';
2
import {HttpClient} from "@angular/common/http";
3

    
4

    
5
import {EnvProperties} from '../properties/env-properties';
6
import {of} from "rxjs";
7

    
8
@Injectable()
9
export class HelperService {
10
    constructor(private http: HttpClient) {}
11

    
12
    /**
13
    * @deprecated
14
    */
15
    getHelper (router: string, position: string, before: boolean, div: string, properties:EnvProperties, communityId:string ):any {
16
        //console.info("get router helpText for : "+router+" - position="+position+" - before="+before + " - div="+div);
17

    
18
        let url = properties.adminToolsAPIURL;
19
        if(div) {
20
          url += '/divhelpcontent?active=true&community='+communityId+'&page='+router+'&div=' + div;
21
        } else {
22
          url += '/pagehelpcontent?active=true&community='+communityId+'&page='+router+'&position=' + position;
23
          if(before) {
24
            url += '&before='+before;
25
          }
26
        }
27

    
28
        return this.http.get((properties.useLongCache)? (properties.cacheUrl+encodeURIComponent(url)): url);
29
                    //.map(res => <any> res.json());
30

    
31
    }
32

    
33
    getPageHelpContents(properties:EnvProperties, communityId:string, router: string):any {
34
      if(!communityId) {
35
        communityId = properties.adminToolsCommunity;
36
      }
37
      if(!communityId) {
38
        communityId = 'openaire';
39
      }
40
      if(typeof properties.useHelpTexts ==  "undefined" || properties.useHelpTexts) {
41
        let page_route: string = router.split('?')[0].substring(0);
42
        let url = properties.adminToolsAPIURL;
43
        url += '/' + properties.adminToolsPortalType + '/' + communityId + '/pagehelpcontent/grouped?active=true&page=' +
44
          ((page_route.indexOf("/"+communityId+"/")!=-1 ) ? ("/" + page_route.split("/"+communityId+"/")[1]) : page_route);
45
        return this.http.get((properties.useLongCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
46
      }else {
47
        return of(null);
48
      }
49
    }
50

    
51
    getDivHelpContents(properties:EnvProperties, communityId:string, router: string):any {
52
      if(!communityId) {
53
        communityId = properties.adminToolsCommunity;
54
      }
55
      if(!communityId) {
56
        communityId = 'openaire';
57
      }
58
      if(typeof properties.useHelpTexts ==  "undefined" || properties.useHelpTexts) {
59
      let page_route: string = router.split('?')[0].substring(0);
60
      let url = properties.adminToolsAPIURL;
61
      url += '/'+properties.adminToolsPortalType+'/' + communityId + '/divhelpcontent/grouped?active=true&page='+
62
        ((page_route.indexOf("/"+communityId+"/")!=-1 ) ? ("/" + page_route.split("/"+communityId+"/")[1]) : page_route);
63
      return this.http.get((properties.useLongCache)? (properties.cacheUrl+encodeURIComponent(url)): url);
64
      }else {
65
        return of(null);
66
      }
67
    }
68

    
69
}
(3-3/4)