VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/libs/absol-full/dist/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-full/dist/js/mdls__absol-poser__fragment__PoserViewer.js
/*** module: node_modules/absol-poser/fragment/PoserViewer.js ***/
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _Fragment = _interopRequireDefault(require("absol/src/AppPattern/Fragment"));

var _Core = require("../dom/Core");

var _OOP = _interopRequireDefault(require("absol/src/HTML5/OOP"));

require("../css/posereditor.css");

var _APEditableSection = _interopRequireDefault(require("../dom/editor/APEditableSection"));

var _APEditableQuestion = _interopRequireDefault(require("../dom/editor/question/APEditableQuestion"));

var _PVSection = _interopRequireDefault(require("../dom/viewer/PVSection"));

var _PVQuestion = _interopRequireDefault(require("../dom/viewer/question/PVQuestion"));

var _ContextMenu = _interopRequireDefault(require("absol-acomp/js/ContextMenu"));

var _ResizeSystem = _interopRequireDefault(require("absol/src/HTML5/ResizeSystem"));

var _PoserQuestionTreeEditor = _interopRequireDefault(require("./PoserQuestionTreeEditor"));

require("../css/poserviewer.css");

var _EventEmitter = _interopRequireDefault(require("absol/src/HTML5/EventEmitter"));

var _utils = require("absol-acomp/js/utils");

var _utils2 = require("../utils");

var _Array = require("absol/src/DataStructure/Array");


/***
 * @extends Fragment
 * @param {*=} opt
 * @constructor
 */
function PoserViewer(opt) {
  this.opt = Object.assign({
    hasScroller: true,
    hasSection: true,
    shuffleQuestion: false
  }, opt);

  _Fragment.default.call(this);

  _EventEmitter.default.call(this);
}

_OOP.default.mixClass(PoserViewer, _Fragment.default, _EventEmitter.default);

PoserViewer.prototype.createView = function () {
  this.$view = (0, _Core._)({
    class: 'ap-poser-viewer',
    child: [{
      class: 'ap-poser-viewer-header'
    }, {
      class: 'ap-poser-viewer-body'
    }, {
      class: 'ap-poser-viewer-footer'
    }],
    on: {
      contextmenu: this.ev_contextMenu.bind(this)
    }
  });
  this.$view.poserViewer = this;
  this.$body = (0, _Core.$)('.ap-poser-viewer-body', this.$view);
  this.$attachhook = (0, _Core._)('attachhook').addTo(this.$view);
  this.$attachhook.requestUpdateSize = this.updateSize.bind(this);
  var self = this;
  this.$attachhook.on('attached', function () {
    _ResizeSystem.default.add(this);

    this.requestUpdateSize();
    self.start();
  });

  if (!this.opt.hasScroller) {
    this.$view.addClass('ap-without-scroller');
  }

  if (!this.opt.hasSection) {
    this.$view.addClass('ap-without-section');
  }

  if (this.opt.readOnly) {
    this.$view.addClass('ap-read-only');
  }
};
/***
 *
 * @param {Array<APSectionData>} data
 * @param {Array<number>=} order
 */


PoserViewer.prototype.setData = function (data, order) {
  this._originalData = this.normalizeData(data);
  this._sections = this._originalData;
  this._orders = [];

  if (order) {
    this._orders = order.slice();
  } else {
    this._sections.forEach(stn => {
      var idArr = stn.questions.map(qt => qt.ident);

      if (this.opt.shuffleQuestion) {
        (0, _Array.arrayShuffle)(idArr);
      }

      this._orders.push.apply(this._orders, idArr);
    });
  }

  this._id2order = this._orders.reduce((ac, cr, i) => {
    ac[cr] = i;
    return ac;
  }, {});
  this.$body.clearChild();
  var qtCount = 0;

  this._sections.forEach(function (stn, i) {
    var gElt = this._makeSectionGroup(stn, i + 1, qtCount + 1);

    qtCount += stn.questions.length;
    this.$body.addChild(gElt);
  }.bind(this));

  setTimeout(() => {
    console.log(this.getOrder());
  }, 1000);
};

PoserViewer.prototype.normalizeData = function (data) {
  var dict = {};
  var count = 1;
  var needIdent = [];
  data = data || [];
  data = data instanceof Array ? data : [data];
  data = data.map(function (oGroup) {
    var group = Object.assign({}, oGroup);
    group.section = Object.assign({}, oGroup.section);

    if (!group.section.ident || !(group.section.ident > 0)) {
      needIdent.push(group.section);
    } else {
      dict[group.section.ident] = true;
    }

    group.questions = (oGroup.questions || []).map(function (oQuestion) {
      var question = Object.assign({}, oQuestion);
      delete question.correct_answer;

      if (!question.ident || !(question.ident > 0)) {
        needIdent.push(question);
      } else {
        dict[question.ident] = true;
      }

      if (question.answer && question.answer instanceof Array) {
        question.answer = oQuestion.answer.map(function (ans) {
          if (typeof ans === 'object') {
            ans = Object.assign({}, ans);

            if (!ans.ident || !(ans.ident > 0)) {
              needIdent.push(ans);
            } else {
              dict[ans.ident] = true;
            }

            return ans;
          } else return ans;
        });
      }

      return question;
    });
    return group;
  });
  needIdent.forEach(function (it) {
    while (dict[count]) {
      count++;
    }

    it.ident = count;
    count++;
  });
  return data;
};

PoserViewer.prototype.getData = function () {
  return this._originalData;
};

PoserViewer.prototype.getOrder = function () {
  if (!this._originalData) return null;

  var originOrders = this._originalData.reduce((ac, cr) => {
    return ac.concat(cr.questions.map(qt => qt.ident + ''));
  }, []);

  var cOrder = this._orders.map(x => x + '');

  if (!this.opt.shuffleQuestion && (0, _Array.arrayCompare)(originOrders, cOrder, true)) {
    return null;
  } else return this._orders.slice();
};

PoserViewer.prototype._makeSectionGroup = function (stnData, stnIdx, qtIdx0) {
  var self = this;
  var stn = {
    tag: _PVSection.default.tag,
    props: {
      data: stnData.section,
      idx: stnIdx
    }
  };
  var sortedQuestions = stnData.questions.slice();
  sortedQuestions.sort((a, b) => {
    return this._id2order[a.ident] - this._id2order[b.ident];
  });
  var questions = sortedQuestions.map((qt, i) => {
    return {
      tag: _PVQuestion.default.tag,
      attr: {
        'data-order': this._id2order[qt.ident]
      },
      props: {
        data: qt,
        idx: qtIdx0 + i,
        readOnly: !!this.opt.readOnly
      },
      on: {
        resultchange: function (event) {
          self.ev_questionResultChange(this, event);
        }
      }
    };
  });
  return (0, _Core._)({
    class: 'ap-section-group',
    child: [stn].concat(questions)
  });
};

PoserViewer.prototype.getResult = function () {
  var count = 1;
  var dict = {
    "0": true
  };

  var getOnce = () => {
    while (dict[count]) ++count;

    dict[count] = true;
    return count;
  };

  var questions = Array.prototype.reduce.call(this.$body.childNodes, function (ac, cr) {
    ac.push.apply(ac, Array.prototype.slice.call(cr.childNodes, 1));
    return ac;
  }, []);
  return questions.reduce(function (ac, qt) {
    var ident = qt.resultIdent;

    if (ident === 0 || !(0, _utils.isNaturalNumber)(ident) || dict[ident]) {
      ident = getOnce();
    } else {
      dict[ident] = true;
    }

    ac[qt.data.ident] = {
      ident: ident,
      value: qt.result
    };
    return ac;
  }, {});
};

PoserViewer.prototype.setResult = function (resultDict) {
  resultDict = resultDict || {};
  var questions = Array.prototype.reduce.call(this.$body.childNodes, function (ac, cr) {
    ac.push.apply(ac, Array.prototype.slice.call(cr.childNodes, 1));
    return ac;
  }, []);
  questions.forEach(function (qt) {
    var questionIdent = qt.data.ident;
    var resultProp = resultDict[questionIdent];

    if (resultProp) {
      qt.result = resultProp.value;
      qt.resultIdent = resultProp.ident;
    }
  });
};

PoserViewer.prototype.ev_contextMenu = function (event) {
  console.log(event.target);
};

PoserViewer.prototype.updateSize = function () {
  var width = this.$view.getBoundingClientRect().width;

  if (!this._prevWidth || this._prevWidth < 500 !== width < 500) {
    if (width < 500) {
      this.$view.addClass('ap-width-s');
    } else {
      this.$view.removeClass('ap-width-s');
    }
  }

  if (!this._prevWidth || this._prevWidth < 390 !== width < 390) {
    if (width < 390) {
      this.$view.addClass('ap-width-xs');
    } else {
      this.$view.removeClass('ap-width-xs');
    }
  }

  this._prevWidth = width;
};

PoserViewer.prototype.ev_questionResultChange = function (questionElt, event) {
  this.emit('resultchange', {
    target: this,
    type: 'resultchange',
    originalEvent: event.originalEvent || event,
    questionResult: questionElt.result,
    questionData: questionElt.data.export(),
    questionIdent: questionElt.data.ident
  }, this);
};

PoserViewer.prototype.onResume = function () {
  if (this.$view) (0, _utils2.autoThemeVariable)(this.$view);
};

var _default = PoserViewer;
exports.default = _default;

VaKeR 2022