<commit_before>import Ember from 'ember';
import ENUMS from 'irene/enums';
import { task } from 'ember-concurrency';
import { on } from '@ember/object/evented';
import ENV from 'irene/config/environment';
import { translationMacro as t } from 'ember-i18n';

export default Ember.Component.extend({

  i18n: Ember.inject.service(),

  tPleaseTryAgain: t('pleaseTryAgain'),

  vulnerabilities: (function() {
    const store = this.get("store");
    return store.query("security/vulnerability", {'limit':0})
    .then(
      data => store.query("security/vulnerability", {'limit':data.meta.count})
    )
  }).property(),

  fileDetails: (function() {
    const fileId = this.get("file.fileId");
    return this.get("store").findRecord("security/file", fileId);
  }).property(),

  ireneFilePath: (function() {
    const fileId = this.get("file.fileId");
    const ireneHost = ENV.ireneHost;
    return [ireneHost, "file", fileId].join('/');
  }).property(),

  setApiScanStatus: task(function * () {
    let isApiDone = this.$("#api-scan-status").is(":checked");
    let apiScanStatus = ENUMS.SCAN_STATUS.UNKNOWN;
    if(isApiDone) apiScanStatus = ENUMS.SCAN_STATUS.COMPLETED;
    const file = yield this.get("fileDetails")
    yield file.set('apiScanStatus', apiScanStatus);
    yield file.save();
  }).evented(),

  setApiScanStatusSucceeded: on('setApiScanStatus:succeeded', function() {
    this.get('notify').success('Successfully saved the API scan status');
  }),

  setApiScanStatusErrored: on('setApiScanStatus:errored', function(_, error) {
    let errMsg = this.get('tPleaseTryAgain');
    if (error.errors && error.errors.length) {
      errMsg = error.errors[0].detail || errMsg;
    } else if(error.message) {
      errMsg = error.message;
    }
    this.get("notify").error(errMsg);
  }),

  openPurgeAPIAnalysisConfirmBox: task(function * () {
    yield this.set('showPurgeAPIAnalysisConfirmBox', true);
  }),

  confirmPurge: task(function * () {
    this.set('isPurgingAPIAnalysis', true);
    const fileId = this.get("file.fileId");
    const url = [ENV.endpoints.files,fileId, ENV.endpoints.purgeAPIAnalyses].join('/');
    return yield this.get("ajax").post(url, { namespace: 'api/hudson-api'})
  }).evented(),

  confirmPurgeSucceeded: on('confirmPurge:succeeded', function() {
    const fileId = this.get("file.fileId");
    this.get("store").findRecord("security/file", fileId);
    this.get('notify').success('Successfully Purged the Analysis');
    this.set('isPurgingAPIAnalysis', false);
    this.set('showPurgeAPIAnalysisConfirmBox', false);
  }),

  confirmPurgeErrored: on('confirmPurge:errored', function(_, error) {
    let errMsg = this.get('tPleaseTryAgain');
    if (error.errors && error.errors.length) {
      errMsg = error.errors[0].detail || errMsg;
    } else if(error.message) {
      errMsg = error.message;
    }

    this.get("notify").error(errMsg);

    this.set('isPurgingAPIAnalysis', false);
  }),

  openAddAnalysisModal: task(function *() {
    yield this.set("showAddAnalysisModal", true);
  }),

  selectVulnerabilty: task(function *(value) {
    yield this.set("selectedVulnerability", value);
  }).evented(),

  downloadApp: task(function *() {
    const fileId = this.get("file.fileId");
    const url = [ENV.endpoints.apps, fileId].join('/');
    const data = yield this.get("ajax").request(url, { namespace: 'api/hudson-api'})
    try {
      window.location = data.url;
    }
    catch(e) {
      throw e;
    }
  }),

  downloadAppErrored: on('downloadApp:errored', function(_, error) {
    let errMsg = this.get('tPleaseTryAgain');
    if (error.errors && error.errors.length) {
      errMsg = error.errors[0].detail || errMsg;
    } else if(error.message) {
      errMsg = error.message;
    }
    this.get("notify").error(errMsg);
  }),

  addAnalysis: task(function *() {
    const vulnerability = this.get("selectedVulnerability");
    const file = this.get("fileDetails");

    if(Ember.isEmpty(vulnerability)) {
      return this.get("notify").error("Please select a vulnerability");
    }

    const analysis = yield this.get("store").createRecord('security/analysis',
      {
        vulnerability: vulnerability,
        file: file
      }
    );
    try {
      yield analysis.save();
    }
    catch(e) {
      analysis.unloadRecord();
      throw e;
    }
  }).evented(),

  addAnalysisSucceeded: on('addAnalysis:succeeded', function() {
    this.set("showAddAnalysisModal", false);
    this.get("notify").success("Analysis Added Successfully");
  }),

  addAnalysisErrored: on('addAnalysis:errored', function(_, error) {
    let errMsg = this.get('tPleaseTryAgain');
    if (error.errors && error.errors.length) {
      errMsg = error.errors[0].detail || errMsg;
    } else if(error.message) {
      errMsg = error.message;
    }
    this.get("notify").error(errMsg);
  }),

  actions: {
    generateReport() {
      const fileId = this.get("file.fileId");
      const emails = this.get("emails");
      let data = {
      };
      if(!Ember.isEmpty(emails)) {
        data = {
          emails: emails.split(",").map(item => item.trim())
        };
      }
      this.set("isGeneratingReport", true);
      const url = [ENV.endpoints.reports, fileId].join('/');
      return this.get("ajax").put(url, { namespace: 'api/hudson-api', data, contentType: 'application/json'})
      .then(() => {
        this.set("isGeneratingReport", false);
        this.set("reportGenerated", true);
        this.set("emailIDs", emails.split(','));
        this.set("emails", "");
      }, (error) => {
        this.set("isGeneratingReport", false);
        for (error of error.errors) {
          this.get("notify").error(error.detail.error);
        }
      });
    },

    openGenerateReportModal() {
      this.set("reportGenerated", false);
      this.set("showGenerateReportModal", true);
    },

    confirmPurgeAPIAnalysisConfirmBox() {
      this.get('confirmPurge').perform();
    }
  }

});
<commit_msg>use the prop way to get the checked property<commit_after>import Ember from 'ember';
import ENUMS from 'irene/enums';
import { task } from 'ember-concurrency';
import { on } from '@ember/object/evented';
import ENV from 'irene/config/environment';
import { translationMacro as t } from 'ember-i18n';

export default Ember.Component.extend({

  i18n: Ember.inject.service(),

  tPleaseTryAgain: t('pleaseTryAgain'),

  vulnerabilities: (function() {
    const store = this.get("store");
    return store.query("security/vulnerability", {'limit':0})
    .then(
      data => store.query("security/vulnerability", {'limit':data.meta.count})
    )
  }).property(),

  fileDetails: (function() {
    const fileId = this.get("file.fileId");
    return this.get("store").findRecord("security/file", fileId);
  }).property(),

  ireneFilePath: (function() {
    const fileId = this.get("file.fileId");
    const ireneHost = ENV.ireneHost;
    return [ireneHost, "file", fileId].join('/');
  }).property(),

  setApiScanStatus: task(function * () {
    let isApiDone = this.$("#api-scan-status").prop('checked');
    let apiScanStatus = ENUMS.SCAN_STATUS.UNKNOWN;
    if(isApiDone) apiScanStatus = ENUMS.SCAN_STATUS.COMPLETED;
    const file = yield this.get("fileDetails")
    file.set('apiScanStatus', apiScanStatus);
    yield file.save();
  }).evented(),

  setApiScanStatusSucceeded: on('setApiScanStatus:succeeded', function() {
    this.get('notify').success('Successfully saved the API scan status');
  }),

  setApiScanStatusErrored: on('setApiScanStatus:errored', function(_, error) {
    let errMsg = this.get('tPleaseTryAgain');
    if (error.errors && error.errors.length) {
      errMsg = error.errors[0].detail || errMsg;
    } else if(error.message) {
      errMsg = error.message;
    }
    this.get("notify").error(errMsg);
  }),

  openPurgeAPIAnalysisConfirmBox: task(function * () {
    yield this.set('showPurgeAPIAnalysisConfirmBox', true);
  }),

  confirmPurge: task(function * () {
    this.set('isPurgingAPIAnalysis', true);
    const fileId = this.get("file.fileId");
    const url = [ENV.endpoints.files,fileId, ENV.endpoints.purgeAPIAnalyses].join('/');
    return yield this.get("ajax").post(url, { namespace: 'api/hudson-api'})
  }).evented(),

  confirmPurgeSucceeded: on('confirmPurge:succeeded', function() {
    const fileId = this.get("file.fileId");
    this.get("store").findRecord("security/file", fileId);
    this.get('notify').success('Successfully Purged the Analysis');
    this.set('isPurgingAPIAnalysis', false);
    this.set('showPurgeAPIAnalysisConfirmBox', false);
  }),

  confirmPurgeErrored: on('confirmPurge:errored', function(_, error) {
    let errMsg = this.get('tPleaseTryAgain');
    if (error.errors && error.errors.length) {
      errMsg = error.errors[0].detail || errMsg;
    } else if(error.message) {
      errMsg = error.message;
    }

    this.get("notify").error(errMsg);

    this.set('isPurgingAPIAnalysis', false);
  }),

  openAddAnalysisModal: task(function *() {
    yield this.set("showAddAnalysisModal", true);
  }),

  selectVulnerabilty: task(function *(value) {
    yield this.set("selectedVulnerability", value);
  }).evented(),

  downloadApp: task(function *() {
    const fileId = this.get("file.fileId");
    const url = [ENV.endpoints.apps, fileId].join('/');
    const data = yield this.get("ajax").request(url, { namespace: 'api/hudson-api'})
    try {
      window.location = data.url;
    }
    catch(e) {
      throw e;
    }
  }),

  downloadAppErrored: on('downloadApp:errored', function(_, error) {
    let errMsg = this.get('tPleaseTryAgain');
    if (error.errors && error.errors.length) {
      errMsg = error.errors[0].detail || errMsg;
    } else if(error.message) {
      errMsg = error.message;
    }
    this.get("notify").error(errMsg);
  }),

  addAnalysis: task(function *() {
    const vulnerability = this.get("selectedVulnerability");
    const file = this.get("fileDetails");

    if(Ember.isEmpty(vulnerability)) {
      return this.get("notify").error("Please select a vulnerability");
    }

    const analysis = yield this.get("store").createRecord(
      'security/analysis', {
        vulnerability: vulnerability,
        file: file
      }
    );
    try {
      yield analysis.save();
    }
    catch(e) {
      analysis.unloadRecord();
      throw e;
    }
  }).evented(),

  addAnalysisSucceeded: on('addAnalysis:succeeded', function() {
    this.set("showAddAnalysisModal", false);
    this.get("notify").success("Analysis Added Successfully");
  }),

  addAnalysisErrored: on('addAnalysis:errored', function(_, error) {
    let errMsg = this.get('tPleaseTryAgain');
    if (error.errors && error.errors.length) {
      errMsg = error.errors[0].detail || errMsg;
    } else if(error.message) {
      errMsg = error.message;
    }
    this.get("notify").error(errMsg);
  }),

  actions: {
    generateReport() {
      const fileId = this.get("file.fileId");
      const emails = this.get("emails");
      let data = {
      };
      if(!Ember.isEmpty(emails)) {
        data = {
          emails: emails.split(",").map(item => item.trim())
        };
      }
      this.set("isGeneratingReport", true);
      const url = [ENV.endpoints.reports, fileId].join('/');
      return this.get("ajax").put(url, { namespace: 'api/hudson-api', data, contentType: 'application/json'})
      .then(() => {
        this.set("isGeneratingReport", false);
        this.set("reportGenerated", true);
        this.set("emailIDs", emails.split(','));
        this.set("emails", "");
      }, (error) => {
        this.set("isGeneratingReport", false);
        for (error of error.errors) {
          this.get("notify").error(error.detail.error);
        }
      });
    },

    openGenerateReportModal() {
      this.set("reportGenerated", false);
      this.set("showGenerateReportModal", true);
    },

    confirmPurgeAPIAnalysisConfirmBox() {
      this.get('confirmPurge').perform();
    }
  }

});

{'fraction_non_alphanumeric': 0.16871396339934822, 'fraction_numerical': 0.0015041363750313362, 'mean_word_length': 3.421130402659771, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5191414', 'n_tokens_mistral': 3898, 'n_tokens_neox': 3770, 'n_words': 672}