Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
discourse-annotator / app / views / annotator / application / _project_selector.html.erb
Size: Mime:
<%= label :project_selector,
          :selected_project_id,
          'Current project',
          { style: 'text-transform:uppercase; color:gray; font-size:.75rem; font-weight:normal;' }
%>


<select class="form-control" id="project_dropdown"
        style="margin-top:5px; margin-bottom:10px;"
        name="project_selector[selected_project_id]">
  <% options = [['Select project', nil]]
     DiscourseAnnotator::Project.order(:name).each { |u| options.push([u.name, u.id]) }
  %>
  <%= options_for_select(options.to_h, @project&.id) %>
</select>


<script type="text/javascript">
    const selectDropdown = document.getElementById('project_dropdown')

    selectDropdown.onchange = (event) => {
        const currentURL = window.location.href;
        const projectId = event.target.value;
        const urlObj = new URL(currentURL);
        if (!!projectId) {
            // Avoid including items previously selected in another project in a copy/move action.
            localStorage.removeItem('checkboxValues');
            localStorage.removeItem('annotationsCheckboxValues');

            const topicId = getTopicId(currentURL);
            if (Boolean(topicId)) {
                window.location.href = `/annotator/projects/${projectId}/topics/${topicId}`
            } else {
                let collectionName
                if (/^\/annotator\/projects\/\d+\/topics$/.test(urlObj.pathname)) {
                    collectionName = 'topics'
                } else if (/^\/annotator\/projects\/\d+\/annotations$/.test(urlObj.pathname)) {
                    collectionName = 'annotations'
                } else {
                    collectionName = 'codes'
                }
                window.location.href = `/annotator/projects/${projectId}/${collectionName}${urlObj.search}`
            }
        }
    }

    function getTopicId(url) {
        const match = url.match(/\/annotator\/projects\/\d+\/topics\/(\d+)/);
        return (match && match[1]) ? match[1] : null;
    }
</script>