0

所以我正在研究这个伪造样本:https ://github.com/Autodesk-Forge/bim360-csharp-issues

我正在努力对 PropertyPanel 中描述的问题进行分类。我在问我不确定该怎么做?

目前,该示例使用查看器加载您的 BIM36O 文档,查看器上有一个扩展程序,单击该扩展程序会一一显示所有问题。这些问题目前按 (Issue1,Issue2,Issue3) 排序。

在问题显示在面板上之前,我已手动使用这行代码对问题进行排序:

 _this.issues = _.sortBy(_this.issues, function (i) { return i.attributes.title });

我还介绍了带有 onclick 事件的面板按钮,单击按钮后如何对问题进行排序并在面板上重新显示现在排序的问题?

这是我的面板代码:

function BIM360IssuePanel(viewer, container, id, title, options) {

    this.viewer = viewer;
    Autodesk.Viewing.UI.PropertyPanel.call(this, container, id, title, options);
    var _this = this;
    this.scrollContainer.style.height = 'calc(100% - 100px)';
    const controlsContainer = document.createElement('div');
    controlsContainer.classList.add('docking-panel-container-solid-color-a');
    controlsContainer.style.height = '30px';
    controlsContainer.style.padding = '4px';

    const titleButton = document.createElement('button');
    const assignedToButton = document.createElement('button');
    const dueDateButton = document.createElement('button');
    const createdAtButton = document.createElement('button');
    const versionButton = document.createElement('button');

    titleButton.innerText = 'Title';
    versionButton.innerText = 'Version';
    assignedToButton.innerText = 'Assigned To';
    dueDateButton.innerText = 'Due Date';
    createdAtButton.innerText = 'Created At';

    titleButton.style.color = 'black';
    versionButton.style.color = 'black';
    assignedToButton.style.color = 'black';
    dueDateButton.style.color = 'black';
    createdAtButton.style.color = 'black';

    controlsContainer.appendChild(titleButton);
    controlsContainer.appendChild(versionButton);
    controlsContainer.appendChild(assignedToButton);
    controlsContainer.appendChild(dueDateButton);
    controlsContainer.appendChild(createdAtButton);
    this.container.appendChild(controlsContainer);    

    assignedToButton.onclick = function (e) {

    };
    titleButton.onclick = function (e) {

    };
    createdAtButton.onclick = function (e) {

    };

    dueDateButton.onclick = function (e) {

    };
    versionButton.onclick = function (e) {
    };

}

showIssues() 的代码:

BIM360IssueExtension.prototype.showIssues = function () {
    var _this = this;

    //remove the list of last time
    var pushPinExtension = _this.viewer.getExtension(_this.pushPinExtensionName);
    pushPinExtension.removeAllItems();
    pushPinExtension.showAll();
    var selected = getSelectedNode();




    //sorting issues
    _this.issues = _.sortBy(_this.issues, function (i) { return i.attributes.title });
    //_this.issues = _.sortBy(_this.issues, function (i) { if (i.attributes.due_date === null) return ''; else return Date.parse(i.attributes.due_date) }); 
    //_this.issues = _.sortBy(_this.issues, function (i) { return i.attributes.assigned_to_name });
    //_this.issues = _.sortBy(_this.issues, function (i) { return i.attributes.starting_version });
   // _this.issues = _.sortBy(_this.issues, function (i) { return i.attributes.dateCreated });



    _this.issues.forEach(function (issue) {
        var dateCreated = moment(issue.attributes.created_at);

        // show issue on panel
        if (_this.panel) {

            _this.panel.addProperty('Title', issue.attributes.title, 'Issue ' + issue.attributes.identifier);
            _this.panel.addProperty('Assigned to', issue.attributes.assigned_to_name, 'Issue ' + issue.attributes.identifier);
            _this.panel.addProperty('Version', 'V' + issue.attributes.starting_version + (selected.version != issue.attributes.starting_version ? ' (Not current)' : ''), 'Issue ' + issue.attributes.identifier)
            _this.panel.addProperty('Due Date', issue.attributes.due_date, 'Issue ' + issue.attributes.identifier);
            _this.panel.addProperty('Created at', dateCreated.format('MMMM Do YYYY, h:mm a'), 'Issue ' + issue.attributes.identifier);

        }



        // add the pushpin
        var issueAttributes = issue.attributes;
        var pushpinAttributes = issue.attributes.pushpin_attributes;
        if (pushpinAttributes) {
            issue.type = issue.type.replace('quality_', ''); // temp fix during issues > quality_issues migration
            pushPinExtension.createItem({
                id: issue.id,
                label: issueAttributes.identifier,
                status: issue.type && issueAttributes.status.indexOf(issue.type) === -1 ? `${issue.type}-${issueAttributes.status}` : issueAttributes.status,
                position: pushpinAttributes.location,
                type: issue.type,
                objectId: pushpinAttributes.object_id,
                viewerState: pushpinAttributes.viewer_state
            });




        }

    })
    }
4

1 回答 1

1

刚刚对源代码做了一个快速检查,有两个快速的想法:

  1. 如果在单击排序按钮时对问题有一些更新,我建议添加当前排序顺序的状态(sortOrder ),并根据方法showIssues中的sortOrder以不同的方式对问题进行排序,同时单击不同的排序按钮,您可以调用BIM360IssueExtension.prototype.loadIssues()方法来刷新面板中的所有问题。

  2. 如果点击排序按钮时问题列表没有更新,我建议缓存当前问题列表,并在排序按钮中添加一个新的方法,如sortIssueInPanel(),主要步骤应该是清理问题面板,对问题进行排序缓存问题列表,并将这些问题一一添加到问题面板中,示例代码片段应如下所示,但请注意,这只是显示主要步骤的代码片段,我没有测试或验证它,仅供您参考参考:

  var sortIssueInPanel = function(sortOrder){
    var issueExtension = NOP_VIEWER.getExtension('BIM360IssueExtension');
    issueExtension.panel.removeAllProperties()

    // Sort the cached issues by sortOrder
    switch(sortOrder){
      case SORT_ORDER.BY_TITLE:
        issuesCached = _.sortBy(issuesCached, function (i) { return i.attributes.title });
        break;

      case SORT_ORDER.BY_DUE_DATE:
      issuesCached = _.sortBy(issuesCached, function (i) { if (i.attributes.due_date === null) return ''; else return Date.parse(i.attributes.due_date) }); 
        break;

      case SORT_ORDER.BY_ASSIGNED_TO_NAME:
      issuesCached = _.sortBy(issuesCached, function (i) { return i.attributes.assigned_to_name });
        break;

      case SORT_ORDER.BY_DATECREATED:
      issuesCached = _.sortBy(issuesCached, function (i) { return i.attributes.dateCreated });
        break;
        
      default:
        break;
    }


    issuesCached.forEach(function (issue) {
      var dateCreated = moment(issue.attributes.created_at);

      // show issue on panel
      if (issueExtension.panel) {

        issueExtension.panel.addProperty('Title', issue.attributes.title, 'Issue ' + issue.attributes.identifier);
        issueExtension.panel.addProperty('Assigned to', issue.attributes.assigned_to_name, 'Issue ' + issue.attributes.identifier);
        issueExtension.panel.addProperty('Version', 'V' + issue.attributes.starting_version + (selected.version != issue.attributes.starting_version ? ' (Not current)' : ''), 'Issue ' + issue.attributes.identifier)
        issueExtension.panel.addProperty('Due Date', issue.attributes.due_date, 'Issue ' + issue.attributes.identifier);
        issueExtension.panel.addProperty('Created at', dateCreated.format('MMMM Do YYYY, h:mm a'), 'Issue ' + issue.attributes.identifier);
      }
    })
  };

希望能帮助到你。

于 2019-01-25T01:32:19.173 回答