<commit_before>/**
 * Created by <NAME> on 28.02.2017.
 */

import {hash} from 'phovea_core/src/index';
import {IProvenanceGraphDataDescription} from 'phovea_core/src/provenance';
import MixedStorageProvenanceGraphManager from 'phovea_core/src/provenance/MixedStorageProvenanceGraphManager';
import ProvenanceGraph from 'phovea_core/src/provenance/ProvenanceGraph';
import {canWrite, isLoggedIn} from 'phovea_core/src/security';

export default class CLUEGraphManager {
  constructor(private manager: MixedStorageProvenanceGraphManager) {
    //selected by url
  }

  static setGraphInUrl(value: string) {
    hash.removeProp('clue_slide', false);
    hash.removeProp('clue_state', false);
    hash.setProp('clue_graph', value);
  }

  newRemoteGraph() {
    if (isLoggedIn()) {
      CLUEGraphManager.setGraphInUrl('new_remote');
      window.location.reload();
    }
  }

  newGraph() {
    CLUEGraphManager.setGraphInUrl('new');
    window.location.reload();
  }

  loadGraph(desc: any) {
    // reset
    CLUEGraphManager.setGraphInUrl(desc.id);
    window.location.reload();
  }

  get storedSlide() {
    return hash.getInt('clue_slide', null);
  }

  set storedSlide(value: number) {
    if (value !== null) {
      hash.setInt('clue_slide', value);
    } else {
      hash.removeProp('clue_slide');
    }
  }

  get storedState() {
    return hash.getInt('clue_state', null);
  }

  set storedState(value: number) {
    if (value !== null) {
      hash.setInt('clue_state', value);
    } else {
      hash.removeProp('clue_state');
    }
  }

  get isAutoPlay() {
    return hash.has('clue_autoplay');
  }

  list() {
    return this.manager.list();
  }

  delete(graph: IProvenanceGraphDataDescription) {
    return this.manager.delete(graph);
  }

  startFromScratch() {
    hash.removeProp('clue_slide', false);
    hash.removeProp('clue_state', false);
    hash.removeProp('clue_graph');
    window.location.reload();
  }

  importGraph(dump: any, remote = false) {
    (remote ? this.manager.importRemote(dump) : this.manager.importLocal(dump)).then((graph) => {
      this.loadGraph(graph.desc);
    });
  }

  importExistingGraph(graph: IProvenanceGraphDataDescription, extras: any = {}, cleanUpLocal = false) {
    return this.manager.cloneRemote(graph, extras).then((newGraph) => {
      const p = (graph.local && cleanUpLocal) ? this.manager.delete(graph) : Promise.resolve(null);
      return p.then(() => this.loadGraph(newGraph.desc));
    });
  }

  migrateGraph(graph: ProvenanceGraph, extras: any = {}): Promise<ProvenanceGraph> {
    return this.manager.migrateRemote(graph, extras).then((newGraph) => {
      return (graph.desc.local ? this.manager.delete(graph.desc) : Promise.resolve(true)).then(() => {
        CLUEGraphManager.setGraphInUrl(newGraph.desc.id); //just update the reference
        return newGraph;
      });
    });
  }

  editGraphMetaData(graph: IProvenanceGraphDataDescription, extras: any = {}) {
    return this.manager.edit(graph, extras);
  }

  setGraph(graph: ProvenanceGraph) {
    hash.setProp('clue_graph', graph.desc.id);
    return graph;<commit_msg>clean up and just update the graph_id in url<commit_after>/**
 * Created by <NAME> on 28.02.2017.
 */

import {hash} from 'phovea_core/src/index';
import {IProvenanceGraphDataDescription} from 'phovea_core/src/provenance';
import MixedStorageProvenanceGraphManager from 'phovea_core/src/provenance/MixedStorageProvenanceGraphManager';
import ProvenanceGraph from 'phovea_core/src/provenance/ProvenanceGraph';
import {canWrite, isLoggedIn} from 'phovea_core/src/security';

export default class CLUEGraphManager {
  constructor(private manager: MixedStorageProvenanceGraphManager) {
    //selected by url
  }

  static setGraphInUrl(value: string) {
    hash.removeProp('clue_slide', false);
    hash.removeProp('clue_state', false);
    hash.setProp('clue_graph', value);
  }

  newRemoteGraph() {
    if (isLoggedIn()) {
      CLUEGraphManager.setGraphInUrl('new_remote');
      window.location.reload();
    }
  }

  newGraph() {
    CLUEGraphManager.setGraphInUrl('new');
    window.location.reload();
  }

  loadGraph(desc: any) {
    // reset
    CLUEGraphManager.setGraphInUrl(desc.id);
    window.location.reload();
  }

  get storedSlide() {
    return hash.getInt('clue_slide', null);
  }

  set storedSlide(value: number) {
    if (value !== null) {
      hash.setInt('clue_slide', value);
    } else {
      hash.removeProp('clue_slide');
    }
  }

  get storedState() {
    return hash.getInt('clue_state', null);
  }

  set storedState(value: number) {
    if (value !== null) {
      hash.setInt('clue_state', value);
    } else {
      hash.removeProp('clue_state');
    }
  }

  get isAutoPlay() {
    return hash.has('clue_autoplay');
  }

  list() {
    return this.manager.list();
  }

  delete(graph: IProvenanceGraphDataDescription) {
    return this.manager.delete(graph);
  }

  startFromScratch() {
    hash.removeProp('clue_slide', false);
    hash.removeProp('clue_state', false);
    hash.removeProp('clue_graph');
    window.location.reload();
  }

  importGraph(dump: any, remote = false) {
    (remote ? this.manager.importRemote(dump) : this.manager.importLocal(dump)).then((graph) => {
      this.loadGraph(graph.desc);
    });
  }

  importExistingGraph(graph: IProvenanceGraphDataDescription, extras: any = {}, cleanUpLocal = false) {
    return this.manager.cloneRemote(graph, extras).then((newGraph) => {
      const p = (graph.local && cleanUpLocal) ? this.manager.delete(graph) : Promise.resolve(null);
      return p.then(() => this.loadGraph(newGraph.desc));
    });
  }

  migrateGraph(graph: ProvenanceGraph, extras: any = {}): Promise<ProvenanceGraph> {
    return this.manager.migrateRemote(graph, extras).then((newGraph) => {
      return (graph.desc.local ? this.manager.delete(graph.desc) : Promise.resolve(true)).then(() => {
        hash.setProp('clue_graph', newGraph.desc.id); //just update the reference
        return newGraph;
      });
    });
  }

  editGraphMetaData(graph: IProvenanceGraphDataDescription, extras: any = {}) {
    return this.manager.edit(graph, extras);
  }

  setGraph(graph: ProvenanceGraph) {
    hash.setProp('clue_graph', graph.desc.id);
    return graph;
{'fraction_non_alphanumeric': 0.14427542033626903, 'fraction_numerical': 0.0025620496397117695, 'mean_word_length': 3.8120184899845917, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1967985', 'n_tokens_mistral': 2099, 'n_tokens_neox': 2047, 'n_words': 338}