<commit_before><link rel="import" href="/static/polymer/polymer.html">
<link rel="import" href="/static/components/installer-pane.html">
<link rel="import" href="/static/components/installer-list.html">
<link rel="import" href="/static/components/installer-diff.html">
<link rel="import" href="/static/iron-ajax/iron-ajax.html">
<link rel="import" href="/static/paper-button/paper-button.html">

<dom-module id="installer-review">
  <link rel="import" type="css" href="/static/css/lutris.min.css">
  <template>
    <div class="row">
      <div class="col-sm-7">
        <paper-button on-tap="onSwitchDiff" class="btn">Diff</paper-button>
      </div>
      <div class="col-sm-5">
        <paper-button on-tap="onDeleteInstaller" class="btn">Delete</paper-button>

        <paper-button on-tap="onAcceptSubmission" class="btn" hidden="[[isNotRevision]]">Accept</paper-button>
        <paper-button on-tap="onPublishInstaller" class="btn" hidden="[[!isUnpublishedInstaller]]">Publish</paper-button>
        <paper-button on-tap="onClearRevisions" class="btn" hidden="[[hasNoRevision]]">Clear revisions</paper-button>
      </div>
    </div>
    <div class="row">
      <installer-list class="col-sm-2" id="installer-list" installers="[[game.installers]]"></installer-list>
      <div class="col-sm-10 row">
        <installer-pane
          class="col-sm-6"
          id="pane-1"
          source-visible="[[sourceVisible]]"
          installer="[[activeInstaller1]]">
        </installer-pane>
        <installer-pane
          class="col-sm-6"
          id="pane-2"
          source-visible="[[sourceVisible]]"
          installer="[[activeInstaller2]]">
        </installer-pane>
        <installer-diff
          class="col-sm-12"
          hidden="[[sourceVisible]]"
          name="{{objectName}}"
          installer1="[[activeInstaller1]]"
          installer2="[[activeInstaller2]]">
        </installer-diff>
      </div>
    </div>

    <iron-ajax
      auto
      url="/api/installers/game/[[slug]]/revisions"
      headers='{"Authorization": "Token [[apiKey]]"}'
      handle-as="json"
      on-response="handleResponse">
    </iron-ajax>

    <iron-ajax
      id="action-request"
      handle-as="json"
      on-response="handleAction">
    </iron-ajax>
  </template>
  <script>
    class InstallerReview extends Polymer.Element {
      static get is() { return 'installer-review' }

      static get properties() {
        return  {
          slug: String,
          apiKey: String,
          sourceVisible: Boolean,
          game: {
            type: Object,
            default: {},
            notify: true
          },
          selectedObject: {
            type: Object,
            default: {}
          },
          selectedInstaller: Object,
          activeInstaller1: Object,
          activeInstaller2: Object,
          activePane: {
            type: String,
            default: 'pane-1'
          },
          objectName: {
            type: String,
            computed: 'getObjectName(selectedObject)'
          },
          isNotRevision: {
            type: Boolean,
            value: true,
            computed: 'getIsNotRevision(selectedObject)'
          },
          isUnpublishedInstaller: {
            type: Boolean,
            value: false,
            computed: 'getIsUnpublishedInstaller(selectedObject)'
          },
          hasNoRevision: {
            type: Boolean,
            value: true,
            computed: 'getHasNoRevision(selectedInstaller)'
          }
        }
      }

      connectedCallback() {
        super.connectedCallback();
        window.addEventListener('load-installer', this.onLoadInstaller.bind(this));
        window.addEventListener('load-revision', this.onLoadRevision.bind(this));
      }

      ready() {
        super.ready();
        this.sourceVisible = false;
      }

      getInstallerIndex(installerId) {
        for (let i=0; i < this.game.installers.length; i++) {
          let installer = this.game.installers[i];
          if (installer.id === installerId) {
            return i;
          }
        }
      }

      getObjectName(selectedObject) {
        if (!selectedObject) {
          return;
        }
        if ('comment' in selectedObject) {
          return selectedObject.comment;
        } else if ('slug' in selectedObject) {
          return selectedObject.slug;
        }
      }

      getIsNotRevision(selectedObject) {
        if (!selectedObject) {
          return true;
        }
        if ('comment' in selectedObject) {
          return false;
        } else {
          return true;
        }
      }

      getIsUnpublishedInstaller(selectedObject) {
        if (!selectedObject || 'comment' in selectedObject) {
          return false;
        }
        return selectedObject.published === false;
      }

      getHasNoRevision(selectedInstaller) {
        return !selectedInstaller.revisions.length;
      }

      handleResponse(response) {
        this.game = response.detail.__data.response;
      }

      handleAction(response) {
        console.log(response);
      }

      onLoadInstaller(event) {
        const installerSlug = event.detail.installerSlug;

        let selectedInstaller = null;
        this.game.installers.forEach(function(installer) {
          if(installer.slug == installerSlug) {
            selectedInstaller = installer;
          }
        });
        if(selectedInstaller) {
          this.selectedObject = selectedInstaller;
          this.activeInstaller1 = this.activeInstaller2;
          this.activeInstaller2 = selectedInstaller;
        }
      }

      onLoadRevision(event) {
        const installerSlug = event.detail.installerSlug;
        const revisionId = event.detail.revisionId;<commit_msg>Display reason in the review page<commit_after><link rel="import" href="/static/polymer/polymer.html">
<link rel="import" href="/static/components/installer-pane.html">
<link rel="import" href="/static/components/installer-list.html">
<link rel="import" href="/static/components/installer-diff.html">
<link rel="import" href="/static/iron-ajax/iron-ajax.html">
<link rel="import" href="/static/paper-button/paper-button.html">

<dom-module id="installer-review">
  <link rel="import" type="css" href="/static/css/lutris.min.css">
  <template>
    <div class="row">
      <div class="col-sm-7">
        <paper-button on-tap="onSwitchDiff" class="btn">Diff</paper-button>
      </div>
      <div class="col-sm-5">
        <paper-button on-tap="onDeleteInstaller" class="btn">Delete</paper-button>

        <paper-button on-tap="onAcceptSubmission" class="btn" hidden="[[isNotRevision]]">Accept</paper-button>
        <paper-button on-tap="onPublishInstaller" class="btn" hidden="[[!isUnpublishedInstaller]]">Publish</paper-button>
        <paper-button on-tap="onClearRevisions" class="btn" hidden="[[hasNoRevision]]">Clear revisions</paper-button>
      </div>
    </div>
    <div class="row">
      <installer-list class="col-sm-2" id="installer-list" installers="[[game.installers]]"></installer-list>
      <div class="col-sm-10 row">
        <div class="col-sm-12">
          <div style="margin-top: 1em;">
            <p hidden="[[ !hasChangeReason ]]"><strong>Reason: </strong>{{ selectedObject.reason }}</p>
          </div>
        </div>
        <installer-pane
          class="col-sm-6"
          id="pane-1"
          source-visible="[[sourceVisible]]"
          installer="[[activeInstaller1]]">
        </installer-pane>
        <installer-pane
          class="col-sm-6"
          id="pane-2"
          source-visible="[[sourceVisible]]"
          installer="[[activeInstaller2]]">
        </installer-pane>
        <installer-diff
          class="col-sm-12"
          hidden="[[sourceVisible]]"
          name="{{objectName}}"
          installer1="[[activeInstaller1]]"
          installer2="[[activeInstaller2]]">
        </installer-diff>
      </div>
    </div>

    <iron-ajax
      auto
      url="/api/installers/game/[[slug]]/revisions"
      headers='{"Authorization": "Token [[apiKey]]"}'
      handle-as="json"
      on-response="handleResponse">
    </iron-ajax>

    <iron-ajax
      id="action-request"
      handle-as="json"
      on-response="handleAction">
    </iron-ajax>
  </template>
  <script>
    class InstallerReview extends Polymer.Element {
      static get is() { return 'installer-review' }

      static get properties() {
        return  {
          slug: String,
          apiKey: String,
          sourceVisible: Boolean,
          game: {
            type: Object,
            default: {},
            notify: true
          },
          selectedObject: {
            type: Object,
            default: {}
          },
          selectedInstaller: Object,
          activeInstaller1: Object,
          activeInstaller2: Object,
          activePane: {
            type: String,
            default: 'pane-1'
          },
          objectName: {
            type: String,
            computed: 'getObjectName(selectedObject)'
          },
          isNotRevision: {
            type: Boolean,
            value: true,
            computed: 'getIsNotRevision(selectedObject)'
          },
          isUnpublishedInstaller: {
            type: Boolean,
            value: false,
            computed: 'getIsUnpublishedInstaller(selectedObject)'
          },
          hasNoRevision: {
            type: Boolean,
            value: true,
            computed: 'getHasNoRevision(selectedInstaller)'
          },
          hasChangeReason: {
            type: Boolean,
            value: false,
            computed: 'getHasChangeReason(selectedObject)'
          }
        }
      }

      connectedCallback() {
        super.connectedCallback();
        window.addEventListener('load-installer', this.onLoadInstaller.bind(this));
        window.addEventListener('load-revision', this.onLoadRevision.bind(this));
      }

      ready() {
        super.ready();
        this.sourceVisible = false;
      }

      getInstallerIndex(installerId) {
        for (let i=0; i < this.game.installers.length; i++) {
          let installer = this.game.installers[i];
          if (installer.id === installerId) {
            return i;
          }
        }
      }

      getObjectName(selectedObject) {
        if (!selectedObject) {
          return;
        }
        if ('comment' in selectedObject) {
          return selectedObject.comment;
        } else if ('slug' in selectedObject) {
          return selectedObject.slug;
        }
      }

      getIsNotRevision(selectedObject) {
        if (!selectedObject) {
          return true;
        }
        if ('comment' in selectedObject) {
          return false;
        } else {
          return true;
        }
      }

      getIsUnpublishedInstaller(selectedObject) {
        if (!selectedObject || 'comment' in selectedObject) {
          return false;
        }
        return selectedObject.published === false;
      }

      getHasNoRevision(selectedInstaller) {
        return !selectedInstaller.revisions.length;
      }

      getHasChangeReason(selectedObject) {
        return (selectedObject && selectedObject.reason && selectedObject.reason != '')
      }

      handleResponse(response) {
        this.game = response.detail.__data.response;
      }

      handleAction(response) {
        console.log(response);
      }

      onLoadInstaller(event) {
        const installerSlug = event.detail.installerSlug;

        let selectedInstaller = null;
        this.game.installers.forEach(function(installer) {
          if(installer.slug == installerSlug) {
            selectedInstaller = installer;
          }
        });
        if(selectedInstaller) {
          this.selectedObject = selectedInstaller;
          this.activeInstaller1 = this.activeInstaller2;
          this.activeInstaller2 = selectedInstaller;
        }
      }

      onLoadRevision(event) {
        const installerSlug = event.detail.installerSlug;
        const revisionId = event.detail.revisionId;
{'fraction_non_alphanumeric': 0.1325811001410437, 'fraction_numerical': 0.004231311706629055, 'mean_word_length': 2.0742157612853864, 'pattern_counts': {'":': 2, '<': 99, '<?xml version=': 0, '>': 97, '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': '3385693', 'n_tokens_mistral': 3472, 'n_tokens_neox': 3390, 'n_words': 562}