<commit_before>import bus from "./../../helper/bus.js";
import FetchHelper from "./../../helper/fetch.helper";
import StorageHelper from "./../../helper/storage.helper";
import GhpProjectItem from "./../ghp-project-item/ghp-project-item.component.vue";
import GhpProjectColumn from "./../ghp-project-column/ghp-project-column.component.vue";
import GhpColumnCard from "./../ghp-column-card/ghp-column-card.component.vue";

export default {
  name: "ghpContent",
  components: {
    "ghp-project-item": GhpProjectItem,
    "ghp-project-column": GhpProjectColumn,
    "ghp-column-card": GhpColumnCard
  },
  data () {
    return {
      currentSearchInput: {},
      errorMessage: "",
      projects: {},
      projectIds: [],
      projectsKey: "",
      projectColumns: {},
      projectColumnIds: [],
      projectColumnsKey: "",
      projectColumnCards: {},
      projectColumnCardIds: [],
      projectColumnCardsKey: "",
      projectsNonAvailable: true,
      columnsNonAvailable: true,
      cardsNonAvailable: true,
    }
  },
  created () {
    bus.$on("search-changed", this.onSearchChanged);
    bus.$on("clear-content", this.onClearContent);
    bus.$on("show-project-columns", this.onShowProjectColumns);
    bus.$on("show-column-cards", this.onShowColumnCards);
  },
  destroyed () {
    bus.$off("search-changed", this.onSearchChanged);
    bus.$off("clear-content", this.onClearContent);
    bus.$off("show-project-columns", this.onShowProjectColumns);
    bus.$off("show-column-cards", this.onShowColumnCards);
  },
  methods: {
    onSearchChanged (searchInput) {
      if (searchInput) {
        this.currentSearchInput = searchInput;
        this.projectsKey = JSON.stringify(searchInput);
        this._fetchProjectsData(searchInput);
      } else {
        this.currentSearchInput = null;
        this.errorMessage = "Error username and/or repo is empty!";
        this._clearData();
      }
    },
    onClearContent () {
      this.currentSearchInput = null;
      this._clearData();
    },
    onShowProjectColumns (projectId) {
      if (projectId) {
        this.projectColumnsKey = projectId;
        this._fetchColumnsData(projectId);
        this._fetchCardsData(-1);
      }
    },
    onShowColumnCards (columnId) {
      if (columnId) {
        this.projectColumnCardsKey = columnId;
        this._fetchCardsData(columnId);
      }
    },
    _fetchProjectsData (search) {
      if (this.projects.hasOwnProperty(this.projectsKey)) return;
      
      const fh = new FetchHelper(StorageHelper.get(StorageHelper.Keys.USER), 
                                  StorageHelper.get(StorageHelper.Keys.PW));

      fh.getProjectsData(search.username, search.repo)
        .then(result => {
          if (result.length > 0) {
            this.$set(this.projects, this.projectsKey, result);
            this.projectIds = result.map(project => { return { id: project.id, name: project.name }});
            this.projectsNonAvailable = false;
          } else {
            this._clearData();
          }
        })
        .catch(error => this.errorMessage = error.message);
    },
    _fetchColumnsData (id) {
      // if (this.projectColumns.hasOwnProperty(this.projectColumnsKey)) return;

      const fh = new FetchHelper(StorageHelper.get(StorageHelper.Keys.USER),
                                  StorageHelper.get(StorageHelper.Keys.PW));

      fh.getColumnsDataById(id)
        .then(result => {
          if (result.length > 0) {
            this.$set(this.projectColumns, this.projectColumnsKey, result);
            this.projectColumnIds = result.map(column => { return { id: column.id, name: column.name }});
            this.columnsNonAvailable = false;
          } else {
            this.columnsNonAvailable = true;
          }
        })
        .catch(error => this.errorMessage = error.message);
    },
    _fetchCardsData (id) {
      if (id === -1) {
        this.projectColumnCards = {};
        this.projectColumnCardsKey = "";
        this.cardsNonAvailable = true;
        return;
      }

      // if (this.projectColumnCards.hasOwnProperty(this.projectColumnCardsKey)) return;

      const fh = new FetchHelper(StorageHelper.get(StorageHelper.Keys.USER),
                                  StorageHelper.get(StorageHelper.Keys.PW));

      fh.getCardsDataById(id)
        .then(result => {
          if (result.length > 0) {
            this.$set(this.projectColumnCards, this.projectColumnCardsKey, result);
            this.projectColumnCardIds = result.map(card => card.id);
            this.cardsNonAvailable = false;
          } else {
            this.cardsNonAvailable = true;
          }
        })
        .catch(error => this.errorMessage = error.message);
    },
    _clearData () {
      this.projectsNonAvailable = true;
      this.columnsNonAvailable = true;
      this.cardsNonAvailable = true;
      this.projects = {};
      this.projectIds = [];
      this.projectsKey = "";
      this.projectColumns = {};
      this.projectColumnIds = [];
      this.projectColumnsKey = "";
      this.projectColumnCards = {};
      this.projectColumnCardIds = [];
      this.projectColumnCardsKey = "";
    }
  }
}<commit_msg>#1 - use single FetchHelper instance<commit_after>import bus from "./../../helper/bus.js";
import FetchHelper from "./../../helper/fetch.helper";
import StorageHelper from "./../../helper/storage.helper";
import GhpProjectItem from "./../ghp-project-item/ghp-project-item.component.vue";
import GhpProjectColumn from "./../ghp-project-column/ghp-project-column.component.vue";
import GhpColumnCard from "./../ghp-column-card/ghp-column-card.component.vue";

export default {
  name: "ghpContent",
  components: {
    "ghp-project-item": GhpProjectItem,
    "ghp-project-column": GhpProjectColumn,
    "ghp-column-card": GhpColumnCard
  },
  data () {
    return {
      __fetcher: null,
      currentSearchInput: {},
      errorMessage: "",
      projects: {},
      projectIds: [],
      projectsKey: "",
      projectColumns: {},
      projectColumnIds: [],
      projectColumnsKey: "",
      projectColumnCards: {},
      projectColumnCardIds: [],
      projectColumnCardsKey: "",
      projectsNonAvailable: true,
      columnsNonAvailable: true,
      cardsNonAvailable: true,
    }
  },
  created () {
    this._init();
    bus.$on("search-changed", this.onSearchChanged);
    bus.$on("clear-content", this.onClearContent);
    bus.$on("show-project-columns", this.onShowProjectColumns);
    bus.$on("show-column-cards", this.onShowColumnCards);
  },
  destroyed () {
    bus.$off("search-changed", this.onSearchChanged);
    bus.$off("clear-content", this.onClearContent);
    bus.$off("show-project-columns", this.onShowProjectColumns);
    bus.$off("show-column-cards", this.onShowColumnCards);
  },
  methods: {
    onSearchChanged (searchInput) {
      if (searchInput) {
        this.currentSearchInput = searchInput;
        this.projectsKey = JSON.stringify(searchInput);
        this._fetchProjectsData(searchInput);
      } else {
        this.currentSearchInput = null;
        this.errorMessage = "Error username and/or repo is empty!";
        this._clearData();
      }
    },
    onClearContent () {
      this.currentSearchInput = null;
      this._clearData();
    },
    onShowProjectColumns (projectId) {
      if (projectId) {
        this.projectColumnsKey = projectId;
        this._fetchColumnsData(projectId);
        this._fetchCardsData(-1);
      }
    },
    onShowColumnCards (columnId) {
      if (columnId) {
        this.projectColumnCardsKey = columnId;
        this._fetchCardsData(columnId);
      }
    },
    _init () {
      if (!this.__fetcher) {
        this.__fetcher = new FetchHelper(StorageHelper.get(StorageHelper.Keys.USER),
                                          StorageHelper.get(StorageHelper.Keys.PW));
      }
    },
    _fetchProjectsData (search) {
      if (this.projects.hasOwnProperty(this.projectsKey)) return;
      
      this.__fetcher.getProjectsData(search.username, search.repo)
        .then(result => {
          if (result.length > 0) {
            this.$set(this.projects, this.projectsKey, result);
            this.projectIds = result.map(project => { return { id: project.id, name: project.name }});
            this.projectsNonAvailable = false;
          } else {
            this._clearData();
          }
        })
        .catch(error => this.errorMessage = error.message);
    },
    _fetchColumnsData (id) {
      this.__fetcher.getColumnsDataById(id)
        .then(result => {
          if (result.length > 0) {
            this.$set(this.projectColumns, this.projectColumnsKey, result);
            this.projectColumnIds = result.map(column => { return { id: column.id, name: column.name }});
            this.columnsNonAvailable = false;
          } else {
            this.columnsNonAvailable = true;
          }
        })
        .catch(error => this.errorMessage = error.message);
    },
    _fetchCardsData (id) {
      if (id === -1) {
        this.projectColumnCards = {};
        this.projectColumnCardsKey = "";
        this.cardsNonAvailable = true;
        return;
      }

      this.__fetcher.getCardsDataById(id)
        .then(result => {
          if (result.length > 0) {
            this.$set(this.projectColumnCards, this.projectColumnCardsKey, result);
            this.projectColumnCardIds = result.map(card => card.id);
            this.cardsNonAvailable = false;
          } else {
            this.cardsNonAvailable = true;
          }
        })
        .catch(error => this.errorMessage = error.message);
    },
    _clearData () {
      this.projectsNonAvailable = true;
      this.columnsNonAvailable = true;
      this.cardsNonAvailable = true;
      this.projects = {};
      this.projectIds = [];
      this.projectsKey = "";
      this.projectColumns = {};
      this.projectColumnIds = [];
      this.projectColumnsKey = "";
      this.projectColumnCards = {};
      this.projectColumnCardIds = [];
      this.projectColumnCardsKey = "";
    }
  }
}
{'fraction_non_alphanumeric': 0.1358073823500149, 'fraction_numerical': 0.001094418465824296, 'mean_word_length': 2.351783927975992, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '130440', 'n_tokens_mistral': 2899, 'n_tokens_neox': 2881, 'n_words': 455}