<commit_before>/**
 * dashboard_view.js
 * @flow weak
 */

import _ from "lodash";
import Marionette from "backbone.marionette";
import DashboardTaskListView from "dashboard/views/dashboard_task_list_view";
import ExplorativeTracingListView from "dashboard/views/explorative_tracing_list_view";
import LoggedTimeView from "dashboard/views/logged_time_view";
import DatasetSwitchView from "dashboard/views/dataset/dataset_switch_view";

class DashboardView extends Marionette.View {
  viewCache: Object;

  static initClass() {
    this.prototype.className = "container wide";
    this.prototype.id = "dashboard";
    this.prototype.template = _.template(`\
<% if (isAdminView) { %>
  <h3>User: <%- firstName %> <%- lastName %></h3>
<% } %>
<div class="tabbable" id="tabbable-dashboard">
  <ul class="nav nav-tabs">
    <% if (!isAdminView) { %>
      <li class="active">
        <a href="#" id="tab-datasets" data-target="#placeholder" data-toggle="tab">Datasets</a>
      </li>
    <% } %>
    <li <% if (isAdminView) { %> class="active" <% } %> >
      <a href="#" id="tab-tasks" data-target="#placeholder" data-toggle="tab">Tasks</a>
    <li <% if (isAdminView) { %> class="active" <% } %> >
    </li>
    <li>
      <a href="#" id="tab-explorative" data-target="#placeholder" data-toggle="tab">Explorative Annotations</a>
    </li>
    <% if (isAdminView) { %>
      <li>
        <a href="#" id="tab-logged-time" data-target="#placeholder" data-toggle="tab">Tracked Time</a>
      </li>
    <% } %>
  </ul>
  <div class="tab-content">
    <div class="tab-pane active" id="placeholder"></div>
  </div>
</div>\
`);

    this.prototype.regions = { tabPane: ".tab-pane" };

    this.prototype.events = {
      "click #tab-datasets": "showDatasets",
      "click #tab-tasks": "showTasks",
      "click #tab-explorative": "showExplorative",
      "click #tab-logged-time": "showLoggedTime",
    };
  }

  // Cannot be ES6 style function, as these are covariant by default
  templateContext = function templateContext() {
    return { isAdminView: this.options.isAdminView };
  };

  initialize(options) {
    this.options = options;
    if (this.options.isAdminView) {
      this.listenTo(this, "render", this.showTasks);
    } else {
      this.listenTo(this, "render", this.showDatasets);
    }

    this.viewCache = {
      datasetSwitchView: null,
      taskListView: null,
      explorativeTracingListView: null,
      loggedTimeView: null,
    };
  }

  showDatasets() {
    return this.showTab("datasetSwitchView", DatasetSwitchView);
  }

  showTasks() {
    return this.showTab("taskListView", DashboardTaskListView);
  }

  showExplorative() {
    return this.showTab("explorativeTracingListView", ExplorativeTracingListView);
  }

  showLoggedTime() {
    return this.showTab("loggedTimeView", LoggedTimeView);
  }

  showTab(viewName, ViewClass) {
    let view = this.viewCache[viewName];
    if (!view) {
      view = this.viewCache[viewName] = new ViewClass(this.options);
    }
    return this.showChildView("tabPane", view, { preventDestroy: true });
  }
}
DashboardView.initClass();

export default DashboardView;<commit_msg>remember which dashboard tab was active and default to that (#1938)<commit_after>/**
 * dashboard_view.js
 * @flow weak
 */

import _ from "lodash";
import Marionette from "backbone.marionette";
import DashboardTaskListView from "dashboard/views/dashboard_task_list_view";
import ExplorativeTracingListView from "dashboard/views/explorative_tracing_list_view";
import LoggedTimeView from "dashboard/views/logged_time_view";
import DatasetSwitchView from "dashboard/views/dataset/dataset_switch_view";

class DashboardView extends Marionette.View {
  viewCache: Object;

  static initClass() {
    this.prototype.className = "container wide";
    this.prototype.id = "dashboard";
    this.prototype.template = _.template(`\
<% if (isAdminView) { %>
  <h3>User: <%- firstName %> <%- lastName %></h3>
<% } %>
<div class="tabbable" id="tabbable-dashboard">
  <ul class="nav nav-tabs">
    <% if (!isAdminView) { %>
      <li class="active">
        <a href="#" id="tab-datasets" data-target="#placeholder" data-toggle="tab">Datasets</a>
      </li>
    <% } %>
    <li <% if (isAdminView) { %> class="active" <% } %> >
      <a href="#" id="tab-tasks" data-target="#placeholder" data-toggle="tab">Tasks</a>
    </li>
    <li>
      <a href="#" id="tab-explorative" data-target="#placeholder" data-toggle="tab">Explorative Annotations</a>
    </li>
    <% if (isAdminView) { %>
      <li>
        <a href="#" id="tab-logged-time" data-target="#placeholder" data-toggle="tab">Tracked Time</a>
      </li>
    <% } %>
  </ul>
  <div class="tab-content">
    <div class="tab-pane active" id="placeholder"></div>
  </div>
</div>\
`);

    this.prototype.regions = { tabPane: ".tab-pane" };

    this.prototype.events = {
      "click #tab-datasets": "showDatasets",
      "click #tab-tasks": "showTasks",
      "click #tab-explorative": "showExplorative",
      "click #tab-logged-time": "showLoggedTime",
    };
  }

  // Cannot be ES6 style function, as these are covariant by default
  templateContext = function templateContext() {
    return { isAdminView: this.options.isAdminView };
  };

  initialize(options) {
    this.options = options;
    if (this.options.isAdminView) {
      this.listenTo(this, "render", this.showTasks);
    } else {
      const tabMethod = localStorage.getItem("lastUsedDashboardTab");
      if (tabMethod && typeof this[tabMethod] === "function") {
        this.listenTo(this, "render", this[tabMethod]);

        setTimeout(() => {
          const mapping = {
            showDatasets: "#tab-datasets",
            showTasks: "#tab-tasks",
            showExplorative: "#tab-explorative",
            showLoggedTime: "#tab-logged-time",
          };

          this.$("li.active").removeClass("active");
          this.$(mapping[tabMethod]).parent().addClass("active");
        }, 100);
      } else {
        this.listenTo(this, "render", this.showDatasets);
      }
    }

    this.viewCache = {
      datasetSwitchView: null,
      taskListView: null,
      explorativeTracingListView: null,
      loggedTimeView: null,
    };
  }

  showDatasets() {
    this.saveLastTab("showDatasets");
    return this.showTab("datasetSwitchView", DatasetSwitchView);
  }

  showTasks() {
    this.saveLastTab("showTasks");
    return this.showTab("taskListView", DashboardTaskListView);
  }

  showExplorative() {
    this.saveLastTab("showExplorative");
    return this.showTab("explorativeTracingListView", ExplorativeTracingListView);
  }

  showLoggedTime() {
    this.saveLastTab("showLoggedTime");
    return this.showTab("loggedTimeView", LoggedTimeView);
  }

  saveLastTab(tabMethod) {
    if (!this.options.isAdminView) {
      localStorage.setItem("lastUsedDashboardTab", tabMethod);
    }
  }

  showTab(viewName, ViewClass) {
    let view = this.viewCache[viewName];
    if (!view) {
      view = this.viewCache[viewName] = new ViewClass(this.options);
    }
    return this.showChildView("tabPane", view, { preventDestroy: true });
  }
}
DashboardView.initClass();

export default DashboardView;
{'fraction_non_alphanumeric': 0.15894501814122244, 'fraction_numerical': 0.001814122243929668, 'mean_word_length': 3.5160680529300565, 'pattern_counts': {'":': 8, '<': 78, '<?xml version=': 0, '>': 79, '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': '4040289', 'n_tokens_mistral': 2385, 'n_tokens_neox': 2307, 'n_words': 432}