<commit_before>/*jshint browser: true */
/*jshint unused: false */
/*global Backbone, $, window, EJS, arangoHelper, _, templateEngine, Joi*/

(function() {
  "use strict";
  var checkMount = function(mount) {
        var regex = /^(\/[^\/\s]+)+$/;
        if (!regex.test(mount)){
      arangoHelper.arangoError("Please give a valid mount point, e.g.: /myPath");
      return false;
    }
    return true;
  };

  window.FoxxActiveView = Backbone.View.extend({
    tagName: 'div',
    className: "tile",
    template: templateEngine.createTemplate("foxxActiveView.ejs"),

    events: {
      'click .icon_arangodb_info' : 'showDocu',
      'click .icon_arangodb_settings2' : 'editFoxxDialog',
      'click .icon' : 'openAppInNewTab'
    },

    initialize: function(){
      this._show = true;
      var mount = this.model.get("mount");
      var isSystem = (
        this.model.get("isSystem") &&
        mount.charAt(0) === '/' &&
          mount.charAt(1) === '_'
      );
      if (isSystem) {
        this.buttonConfig = [];
      } else {
        this.buttonConfig = [
          window.modalView.createDeleteButton(
            "Uninstall", this.uninstall.bind(this)
          ),
          window.modalView.createSuccessButton(
            "Save", this.changeFoxx.bind(this)
          )
        ];
      }
      this.showMod = window.modalView.show.bind(
        window.modalView,
        "modalTable.ejs",
        "Modify Application"
      );
      this.appsView = this.options.appsView;
      _.bindAll(this, 'render');
    },

    toggle: function(type, shouldShow) {
      if (this.model.get("development")) {
        if ("devel" === type) {
          this._show = shouldShow;
        }
      } else {
        if ("active" === type && true === this.model.get("active")) {
          this._show = shouldShow;
        }
        if ("inactive" === type && false === this.model.get("active")) {
          this._show = shouldShow;
        }
      }
      if (this._show) {
        $(this.el).show();
      } else {
        $(this.el).hide();
      }
    },

    fillValues: function() {
      var list = [],
        appInfos = this.model.get("app").split(":"),
        name = appInfos[1],
//        versOptions = [],
        isSystem,
        active,
        modView = window.modalView;
      var mount = this.model.get("mount");
      var editable = !(
        this.model.get("isSystem") &&
        mount.charAt(0) === '/' &&
          mount.charAt(1) === '_'
      );
      if (this.model.get("isSystem")) {
        isSystem = "Yes";
      } else {
        isSystem = "No";
      }
      if (this.model.get("active")) {
        active = "Active";
      } else {
        active = "Inactive";
      }
      list.push(modView.createReadOnlyEntry(
        "id_name", "Name", name
      ));
      if (editable) {
        list.push(modView.createTextEntry(
          "change-mount-point", "Mount", this.model.get("mount"),
          "The path where the app can be reached.",
          "mount-path",
          true,
          [
            {
              rule: Joi.string().required(),
              msg: "No mount-path given."
            }
          ]
        ));
      } else {
        list.push(modView.createReadOnlyEntry(
          "change-mount-point", "Mount", this.model.get("mount")
        ));
      }
      /*
       * For the future, update apps to available newer versions
       * versOptions.push(modView.createOptionEntry(appInfos[2]));
       * list.push(modView.createSelectEntry()
       */
      list.push(modView.createReadOnlyEntry(
        "id_version", "Version", appInfos[2]
      ));
      list.push(modView.createReadOnlyEntry(
        "id_system", "System", isSystem
      ));
      list.push(modView.createReadOnlyEntry(
        "id_status", "Status", active
      ));
      return list;
    },

    editFoxxDialog: function(event) {
      event.stopPropagation();
      var mount = this.model.get("mount");
      var isSystem = (
        this.model.get("isSystem") &&
        mount.charAt(0) === '/' &&
          mount.charAt(1) === '_'
      );
      if (this.model.get("development")) {
        this.buttonConfig[0].disabled = true;
      } else if (!isSystem) {
        delete this.buttonConfig[0].disabled;
      }
      this.showMod(this.buttonConfig, this.fillValues());
    },

    changeFoxx: function() {
      var mount = $("#change-mount-point").val();
      var failed = false;
      var app = this.model.get("app");
      var prefix = this.model.get("options").collectionPrefix;
      if (mount !== this.model.get("mount")) {
        if (checkMount(mount)) {
          $.ajax("foxx/move/" + this.model.get("_key"), {
            async: false,
            type: "PUT",
            data: JSON.stringify({
              mount: mount,
              app: app,
              prefix: prefix
            }),
            dataType: "json",
            error: function(data) {
              failed = true;
              arangoHelper.arangoError(data.responseText);
            }
          });
        } else {
          return;
        }
      }
      // TO_DO change version
      if (!failed) {
        window.modalView.hide();
        this.appsView.reload();
      }
    },

    openAppInNewTab: function() {
      var url = window.location.origin + "/_db/_system" + this.model.get("mount");
      var windowRef = window.open(url, this.model.get("title"));
      windowRef.focus();
    },

    uninstall: function () {
      this.model.destroy({ async: false });
      window.modalView.hide();
      this.appsView.reload();
    },

    showDocu: function(event) {
      event.stopPropagation();
      window.App.navigate(
        "application/documentation/" + encodeURIComponent(this.model.get("_key")),
        {
          trigger: true
        }
      );
    },

    render: function(){
      if (this._show) {
        $(this.el).html(this.template.render(this.model));
      }

      return $(this.el);
    }
  });
}());
<commit_msg>issue #998: Incorrect application URL for non-system Foxx apps<commit_after>/*jshint browser: true */
/*jshint unused: false */
/*global Backbone, $, window, EJS, arangoHelper, _, templateEngine, Joi*/

(function() {
  "use strict";
  var checkMount = function(mount) {
        var regex = /^(\/[^\/\s]+)+$/;
        if (!regex.test(mount)){
      arangoHelper.arangoError("Please give a valid mount point, e.g.: /myPath");
      return false;
    }
    return true;
  };

  window.FoxxActiveView = Backbone.View.extend({
    tagName: 'div',
    className: "tile",
    template: templateEngine.createTemplate("foxxActiveView.ejs"),

    events: {
      'click .icon_arangodb_info' : 'showDocu',
      'click .icon_arangodb_settings2' : 'editFoxxDialog',
      'click .icon' : 'openAppInNewTab'
    },

    initialize: function(){
      this._show = true;
      var mount = this.model.get("mount");
      var isSystem = (
        this.model.get("isSystem") &&
        mount.charAt(0) === '/' &&
          mount.charAt(1) === '_'
      );
      if (isSystem) {
        this.buttonConfig = [];
      } else {
        this.buttonConfig = [
          window.modalView.createDeleteButton(
            "Uninstall", this.uninstall.bind(this)
          ),
          window.modalView.createSuccessButton(
            "Save", this.changeFoxx.bind(this)
          )
        ];
      }
      this.showMod = window.modalView.show.bind(
        window.modalView,
        "modalTable.ejs",
        "Modify Application"
      );
      this.appsView = this.options.appsView;
      _.bindAll(this, 'render');
    },

    toggle: function(type, shouldShow) {
      if (this.model.get("development")) {
        if ("devel" === type) {
          this._show = shouldShow;
        }
      } else {
        if ("active" === type && true === this.model.get("active")) {
          this._show = shouldShow;
        }
        if ("inactive" === type && false === this.model.get("active")) {
          this._show = shouldShow;
        }
      }
      if (this._show) {
        $(this.el).show();
      } else {
        $(this.el).hide();
      }
    },

    fillValues: function() {
      var list = [],
        appInfos = this.model.get("app").split(":"),
        name = appInfos[1],
//        versOptions = [],
        isSystem,
        active,
        modView = window.modalView;
      var mount = this.model.get("mount");
      var editable = !(
        this.model.get("isSystem") &&
        mount.charAt(0) === '/' &&
          mount.charAt(1) === '_'
      );
      if (this.model.get("isSystem")) {
        isSystem = "Yes";
      } else {
        isSystem = "No";
      }
      if (this.model.get("active")) {
        active = "Active";
      } else {
        active = "Inactive";
      }
      list.push(modView.createReadOnlyEntry(
        "id_name", "Name", name
      ));
      if (editable) {
        list.push(modView.createTextEntry(
          "change-mount-point", "Mount", this.model.get("mount"),
          "The path where the app can be reached.",
          "mount-path",
          true,
          [
            {
              rule: Joi.string().required(),
              msg: "No mount-path given."
            }
          ]
        ));
      } else {
        list.push(modView.createReadOnlyEntry(
          "change-mount-point", "Mount", this.model.get("mount")
        ));
      }
      /*
       * For the future, update apps to available newer versions
       * versOptions.push(modView.createOptionEntry(appInfos[2]));
       * list.push(modView.createSelectEntry()
       */
      list.push(modView.createReadOnlyEntry(
        "id_version", "Version", appInfos[2]
      ));
      list.push(modView.createReadOnlyEntry(
        "id_system", "System", isSystem
      ));
      list.push(modView.createReadOnlyEntry(
        "id_status", "Status", active
      ));
      return list;
    },

    editFoxxDialog: function(event) {
      event.stopPropagation();
      var mount = this.model.get("mount");
      var isSystem = (
        this.model.get("isSystem") &&
        mount.charAt(0) === '/' &&
          mount.charAt(1) === '_'
      );
      if (this.model.get("development")) {
        this.buttonConfig[0].disabled = true;
      } else if (!isSystem) {
        delete this.buttonConfig[0].disabled;
      }
      this.showMod(this.buttonConfig, this.fillValues());
    },

    changeFoxx: function() {
      var mount = $("#change-mount-point").val();
      var failed = false;
      var app = this.model.get("app");
      var prefix = this.model.get("options").collectionPrefix;
      if (mount !== this.model.get("mount")) {
        if (checkMount(mount)) {
          $.ajax("foxx/move/" + this.model.get("_key"), {
            async: false,
            type: "PUT",
            data: JSON.stringify({
              mount: mount,
              app: app,
              prefix: prefix
            }),
            dataType: "json",
            error: function(data) {
              failed = true;
              arangoHelper.arangoError(data.responseText);
            }
          });
        } else {
          return;
        }
      }
      // TO_DO change version
      if (!failed) {
        window.modalView.hide();
        this.appsView.reload();
      }
    },

    openAppInNewTab: function() {
      var url = window.location.origin + "/_db/" + 
                encodeURIComponent(arangoHelper.currentDatabase()) + 
                this.model.get("mount");
      var windowRef = window.open(url, this.model.get("title"));
      windowRef.focus();
    },

    uninstall: function () {
      this.model.destroy({ async: false });
      window.modalView.hide();
      this.appsView.reload();
    },

    showDocu: function(event) {
      event.stopPropagation();
      window.App.navigate(
        "application/documentation/" + encodeURIComponent(this.model.get("_key")),
        {
          trigger: true
        }
      );
    },

    render: function(){
      if (this._show) {
        $(this.el).html(this.template.render(this.model));
      }

      return $(this.el);
    }
  });
}());

{'fraction_non_alphanumeric': 0.15856586900720376, 'fraction_numerical': 0.0022356545499710194, 'mean_word_length': 1.8134171907756813, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '5904651', 'n_tokens_mistral': 3671, 'n_tokens_neox': 3637, 'n_words': 635}