<commit_before>CT = {

    taskId: '',
    taskIndex: '',
    tabId: '',
    tab: '',
    tabActive: '',
    prevTabIndex: [],
    inputFocus: false,
    _openCollectionNOWClickTime: new Date(),

    start() {
        say.m('CT.start()')

        CT.prevTabIndex = []

        CT.selectFirstTabOnStart()

        CT.taskId = tabState.selectedTask
        CT.add5()
        CT.loadTasks()
        CT.render()
        CT.events()
    },
    events() {
        say.m('CT.events()')

        document.getElementById('collection-tabs').addEventListener('click', function (e) {
            CT.goToCollection(e)
        })

        document.querySelector('.page-tabs').addEventListener('click', function (e) {
            CT.remoteClassEditing()
        })

        let taskName = document.querySelectorAll('.task-action-container .task-name')
        for (var i = 0; i < taskName.length; i++) {
            taskName[i].addEventListener('click', function (event) {
                CT.overviewTaskNameClickE(event)
            })
            taskName[i].addEventListener('keydown', function (e) {
                CT.overviewTaskNameClickEnterE(e)
            })
        }

    },

    goToCollection(e) {
        say.m('CT.goToCollection(e):')

        //CT.addCollectionTab()

        taskOverlay.inputFocus = true
        CT.add5tab()

        // click on collection tabs
        try {
            if (e.target.parentNode.parentNode.id == 'collection-tabs') {
                if (e.target.parentNode.className.indexOf("active-tab") == -1) {
                    tabState.selectedTask = e.target.parentNode.dataset.taskId.trim()
                    switchToTask(e.target.parentNode.dataset.taskId.trim())
                    sessionRestore.save()
                    CT.render()
                    for (let i = 0; i < tabState.tasks.length; i++) {
                        if (tabState.tasks[i].id == tabState.selectedTask) {
                            if (tabState.tasks[i].name == null) {
                                CT.addClassEditing()

                                //CT.addCollectionTab()
                                document.querySelector('.active-tab').addEventListener('blur', function (e) {
                                    CT._openCollectionNOWClick(e)
                                    CT.remoteClassEditing()
                                    modals.hide()
                                }, true);
                                modals.show('collection')
                            }
                        }
                    }
                } else {
                    CT.addClassEditing()

                    //CT.addCollectionTab()
                    document.querySelector('.active-tab').addEventListener('blur', function (e) {
                        CT._openCollectionNOWClick(e)
                        CT.remoteClassEditing()
                        modals.hide()
                    }, true);
                    modals.show('collection')
                }
            }

        } catch (e) {
        }

        // edit name collection tabs
        document.querySelector('.active-tab input').addEventListener('keydown', function (e) {
            if (e.which == 13) {
                for (let i = 0; i < tabState.tasks.length; i++) {
                    if (tabState.tasks[i].id == e.target.getAttribute('data-id')) {
                        tabState.tasks[i].name = e.target.value
                    }
                }
                sessionRestore.save()
                CT.render()
            }
        })

        CT.add5tab()

        eventEmitter.emit('goToCollection')
    }, _openCollectionNOWClick(e) {
        if (CT._openCollectionNOWClickTime + 5 < new Date() + 1) {
            try {
                if (e.relatedTarget.classList.value == 'openCollectionNOW') {
                    console.log('==================================================================')
                    // console.log(e.relatedTarget.innerText)
                    // console.log(e.relatedTarget.getAttribute("data-links"))
                    // console.log(e.relatedTarget.getAttribute("data-links").split(","))
                    let colName = e.relatedTarget.innerText
                    let arrLinks = e.relatedTarget.getAttribute("data-links").split(",")

                    let id = tasks.addEmpty({name: colName})
                    switchToTask(id)
                    console.log(id)

                    // addTab(tabs.add({url: ''}, tabs[0]), {enterEditMode: false})
                    // addTab(tabs.add({url: ''}, tabs[0]), {enterEditMode: false})
                    // addTab(tabs.add({url: ''}, tabs[0]), {enterEditMode: false})
                    // addTab(tabs.add({url: ''}, tabs[0]), {enterEditMode: false})
                    sessionRestore.save()
                    CT.render()

                    for (let i = 0; i < tabState.tasks.length; i++) {
                        if (tabState.tasks[i].id == id) {
                            for (let j = 0; j < tabState.tasks[i].tabs.length; j++) {
                                if (arrLinks[j]) {
                                    tabState.tasks[i].tabs[j].url = arrLinks[j].split(":")[0]
                                    tabState.tasks[i].tabs[j].title = arrLinks[j].split(":")[1]
                                }
                            }
                        }
                    }
                    rerenderTabstrip()
                    switchToTask(id)
                    if(arrLinks.length>0){
                        openURLFromsearchbar('', arrLinks[0].split(":")[0])
                    }
                    // for (let i = 0; i < arrLinks.length; i++) {
                    //     // console.log(arrLinks[i])
                    //     addTabInNewCol(tabs.add({url: arrLinks[i]}, tabs[0]), {enterEditMode: false}, )
                    // }
                    console.log('==================================================================')
                }
            } catch (e) {
            }
            CT._openCollectionNOWClickTime = new Date() + 1
        }

    },
    goToCollectionID(id) {
        say.m('CT.goToCollectionID(id): ' + id)

        try {
            let index = CT.getIndexFromIdTaskId(id)
            if (index == 0) {
                switchToTask(tabState.tasks[index].id)
            } else {
                switchToTask(tabState.tasks[index - 1].id)
            }

            CT.render()
        } catch (e) {
            CT.render()
            taskOverlay.inputFocus = false
        }

    },
    getIndexFromIdTaskId(id) {
        say.m('CT.getIndexFromIdTaskId(id): ' + id)

        let index = ''

        for (let i = 0; i < tabState.tasks.length; i++) {
            console.log(tabState.tasks[i].id)
            if (tabState.tasks[i].id == id) {
                index = i
            }
        }

        console.log('id: ' + id, 'index: ' + index)
        return index
    },
    addClassEditing() {
        document.querySelector('.active-tab input').disabled = false
        document.querySelector('.active-tab input').select()
        document.querySelector('.active-tab').className += ' editing'
    },
    remoteClassEditing() {
        say.m('CT.remoteClassEditing()')

        try {
            if (document.querySelector('.active-tab ').className.indexOf("editing") != -1) {
                document.querySelector('.active-tab ').classList.remove("editing");
                CT.remoteClassEditing()
            }
        } catch (e) {
        }
    },
    getDataFromE(e) {
        say.m('CT.getDataFromE(e)' + e)

        if (e.target.type == 'text') {
            CT.taskId = e.target.parentElement.dataset.taskId
            CT.taskIndex = e.target.parentElement.dataset.index
        } else {
            CT.taskId = e.target.dataset.taskId
            CT.taskIndex = e.target.dataset.index
        }

        CT.tabId = tabState.tasks[CT.taskIndex].tabs[0].id

        CT.tab = document.querySelector('[data-tab="' + CT.taskIndex + '"]')
        CT.tabActive = document.querySelector('.active-tab.collection-tab')

        CT.prevTabIndex.push(CT.taskIndex) // history tabs

        tabState.selectedTask = tabState.tasks[CT.prevTabIndex[CT.prevTabIndex.length - 1]].id

    },
    selectFirstTabOnStart() {
        tabState.selectedTask = tabState.tasks[0].id
        switchToTask(tabState.selectedTask)
        sessionRestore.save()
    },
    loadTasks() {
        tasks.get().forEach(function (task, index) {
            var el = getTaskElement(task, index)
            taskContainer.appendChild(el)
            taskOverlay.dragula.containers.push(el.getElementsByClassName('task-tabs-container')[0])
        })
    },
    clickOnFirstCollection() {
        document.querySelector('[data-task-id="' + tasks.get()[0].id + ' "]').click()
    },
    add5() {
        say.m('CT.add5()')
        if (tabState.tasks.length < 5) {
            let id = tabState.selectedTask
            for (let i = tabState.tasks.length; i != 5; i++) {
                tasks.add()
            }
        }
    },
    add5tab() {
        say.m('CT.add5tab()')

        for (let i = 0; i < tabState.tasks.length; i++) {
            if (tabState.tasks[i].id == tabState.selectedTask) {
                for (let j = tabState.tasks[i].tabs.length; j < 5; j++) {
                    addTab(tabs.add({url: ''}, tabs[0]), {enterEditMode: false})
                }
            } else {
                if (tabState.tasks[i].tabs.length == 1 && tabState.tasks[i].tabs[0].url == 'duckduckgo.com') {

                    tabState.tasks[i].tabs[0].url = ''
                    tabState.tasks[i].tabs[0].title = ''
                }
            }
        }
    },
    addEmptyTabStyle() {
        say.m('CT.addEmptyTabStyle()')

        let tabViewContents = document.querySelectorAll('.tab-view-contents')
        for (let i = 0; i < tabViewContents.length; i++) {
            if (tabViewContents[i].querySelector('.title').innerText == '...' && !tabViewContents[i].classList.contains('addEmptyTabStyle')) {
                tabViewContents[i].className += " addEmptyTabStyle"
            } else if (tabViewContents[i].classList.contains('addEmptyTabStyle')) {
                tabViewContents[i].classList.remove('addEmptyTabStyle');
            }
        }
    },
    overviewTaskNameClickEnterE(e) {
        say.m('CT.overviewTaskNameClickEnterE()')

        let id = e.target.parentElement.parentElement.getAttribute('data-task')
        let eTarget = e.target
        let eVal = e.target.value
        if (e.which == 13) {
            CT.render()
            for (let i = 0; i < tasks.get().length; i++) {
                if (tasks.get()[i].id == id) {
                    if (i <= 5) {
                        document.querySelector(`[data-index="${i}"]`).click()
                    }
                }
            }
        }
    },
    overviewTaskNameClickE(e) {
        say.m('CT.overviewTaskNameClickE()')

        let id = e.target.parentElement.parentElement.getAttribute('data-task')
        for (let i = 0; i < tasks.get().length; i++) {
            if (tasks.get()[i].id == id) {
                if (i <= 5) {
                    CT.collectionTopClickOnCollectionTab(i)
                    CT.collectionLeftFocusOnCollectionTabInput(id)
                }
            }
        }
    },

    collectionTopClickOnCollectionTab(index) {
        document.querySelector(`[data-index="${index}"]`).click()
    },
    collectionTopRemoveBGSelectedAll() {
        let elems = document.querySelectorAll(".active-tab");
        for (var i = 0; i < elems.length; i++)
            elems[i].classList.remove('active-tab');
    },
    collectionTopAddBGSelected(index) {
        CT.collectionTopRemoveBGSelectedAll()
        document.querySelector(`[data-index="${index}"]`).classList.add('active-tab')
    },
    collectionTopAddBGSelectedById(id_) {
        CT.collectionTopRemoveBGSelectedAll()
        document.querySelector(`[data-task-id="${id_} "]`).classList.add('active-tab')
    },
    collectionLeftFocusOnCollectionTabInput(id) {
        document.querySelector(`[data-task="${id}"] input`).focus()
    },
    addCollectionTab() {
        say.m('CT.addCollectionTab()')

        // let thereIsCollection = false
        // for (let i = 0; i < tabState.tasks.length; i++) {
        //     if (tabState.tasks[i].id == tabState.selectedTask) {
        //         for (let j = 0; j < tabState.tasks[i].tabs.length; j++) {
        //             if (tabState.tasks[i].tabs[j].title == 'Collection') {
        //                 thereIsCollection = true
        //             }
        //
        //         }
        //         if (tabState.tasks[i].tabs.length == 2) {
        //             for (let j = 0; j < tabState.tasks[i].tabs.length; j++) {
        //                 if (tabState.tasks[i].tabs[j].url == 'duckduckgo.com') {
        //                     destroyTab(tabState.tasks[i].tabs[j].id)
        //                 }
        //
        //             }
        //         }
        //         // else if (tabState.tasks[i].tabs.length == 1) {
        //             // alert(tabState.tasks[i].tabs.length)
        //             // console.log('--------------------', tabState.tasks[i].tabs.length)
        //             // tabState.tasks[i].tabs[0].title = 'Collection'
        //             // tabState.tasks[i].tabs[0].url = 'file:///' + __dirname + '/pages/collection/index.html'
        //
        //             // navigate(tabState.tasks[i].tabs[0].id, 'file:///' + __dirname + '/pages/collection/index.html')
        //
        //         // }
        //     }
        // }
        // if (thereIsCollection == false && document.querySelector('.active-tab ').className.indexOf("editing") != -1) {
        //     addTab(tabs.add({
        //         url: 'file:///' + __dirname + '/pages/collection/index.html',
        //         title: 'Collection'
        //     }, tabs[0]), {enterEditMode: false})
        //     CT.addClassEditing()
        // }

    },

    render() {
        say.m('CT.render()')

        CT.add5tab()
        // CT.addEmptyTabStyle()

        if (CT.inputFocus == false) {
            let collectionTabsHTML = []
            for (let i = 0; i < tabState.tasks.length; i++) {
                let val = tabState.tasks[i].name
                if (val == null || val == 'null')
                    val = ''
                let title = `<input placeholder="●●●" type="text" class="collectionTabInput" data-id="${tabState.tasks[i].id}" value="${val}" disabled="true">` || `<input type="text" placeholder="●●●" class="collectionTabInput" data-id="${tabState.tasks[i].id}" value="${val}"  disabled="true"> <svg width="23.9px" height="5.6px">23.9 5.6 <use xlink:href="icons/svg/miniature-controls.svg#ellipsis-big"></use></svg>`
                collectionTabsHTML.push('
' + title + '
')
            }
            document.getElementById('collection-tabs').innerHTML = collectionTabsHTML.join('')
            // CT.addEmptyTabStyle()

            CT.renderOverlay()
            // CT.addEmptyTabStyle()

            eventEmitter.emit('render')

        }
    },
    renderOverlay() {
        say.m('CT.renderOverlay() ' + taskOverlay.inputFocus)

        eventEmitter.emit('renderOverlay')

        if (taskOverlay.inputFocus) {
            if (document.querySelector('#task-overlay').getAttribute('hidden') == null)
                taskOverlay.show()
        }

        eventEmitter.emit('render')

    }

}
CT.start()

<commit_msg>remove console log<commit_after>CT = {

    taskId: '',
    taskIndex: '',
    tabId: '',
    tab: '',
    tabActive: '',
    prevTabIndex: [],
    inputFocus: false,
    _openCollectionNOWClickTime: new Date(),

    start() {
        say.m('CT.start()')

        CT.prevTabIndex = []

        CT.selectFirstTabOnStart()

        CT.taskId = tabState.selectedTask
        CT.add5()
        CT.loadTasks()
        CT.render()
        CT.events()
    },
    events() {
        say.m('CT.events()')

        document.getElementById('collection-tabs').addEventListener('click', function (e) {
            CT.goToCollection(e)
        })

        document.querySelector('.page-tabs').addEventListener('click', function (e) {
            CT.remoteClassEditing()
        })

        let taskName = document.querySelectorAll('.task-action-container .task-name')
        for (var i = 0; i < taskName.length; i++) {
            taskName[i].addEventListener('click', function (event) {
                CT.overviewTaskNameClickE(event)
            })
            taskName[i].addEventListener('keydown', function (e) {
                CT.overviewTaskNameClickEnterE(e)
            })
        }

    },

    goToCollection(e) {
        say.m('CT.goToCollection(e):')

        //CT.addCollectionTab()

        taskOverlay.inputFocus = true
        CT.add5tab()

        // click on collection tabs
        try {
            if (e.target.parentNode.parentNode.id == 'collection-tabs') {
                if (e.target.parentNode.className.indexOf("active-tab") == -1) {
                    tabState.selectedTask = e.target.parentNode.dataset.taskId.trim()
                    switchToTask(e.target.parentNode.dataset.taskId.trim())
                    sessionRestore.save()
                    CT.render()
                    for (let i = 0; i < tabState.tasks.length; i++) {
                        if (tabState.tasks[i].id == tabState.selectedTask) {
                            if (tabState.tasks[i].name == null) {
                                CT.addClassEditing()

                                //CT.addCollectionTab()
                                document.querySelector('.active-tab').addEventListener('blur', function (e) {
                                    CT._openCollectionNOWClick(e)
                                    CT.remoteClassEditing()
                                    modals.hide()
                                }, true);
                                modals.show('collection')
                            }
                        }
                    }
                } else {
                    CT.addClassEditing()

                    //CT.addCollectionTab()
                    document.querySelector('.active-tab').addEventListener('blur', function (e) {
                        CT._openCollectionNOWClick(e)
                        CT.remoteClassEditing()
                        modals.hide()
                    }, true);
                    modals.show('collection')
                }
            }

        } catch (e) {
        }

        // edit name collection tabs
        document.querySelector('.active-tab input').addEventListener('keydown', function (e) {
            if (e.which == 13) {
                for (let i = 0; i < tabState.tasks.length; i++) {
                    if (tabState.tasks[i].id == e.target.getAttribute('data-id')) {
                        tabState.tasks[i].name = e.target.value
                    }
                }
                sessionRestore.save()
                CT.render()
            }
        })

        CT.add5tab()

        eventEmitter.emit('goToCollection')
    }, _openCollectionNOWClick(e) {
        if (CT._openCollectionNOWClickTime + 5 < new Date() + 1) {
            try {
                if (e.relatedTarget.classList.value == 'openCollectionNOW') {
                    let colName = e.relatedTarget.innerText
                    let arrLinks = e.relatedTarget.getAttribute("data-links").split(",")

                    let id = tasks.addEmpty({name: colName})
                    switchToTask(id)

                    sessionRestore.save()
                    CT.render()

                    for (let i = 0; i < tabState.tasks.length; i++) {
                        if (tabState.tasks[i].id == id) {
                            for (let j = 0; j < tabState.tasks[i].tabs.length; j++) {
                                if (arrLinks[j]) {
                                    tabState.tasks[i].tabs[j].url = arrLinks[j].split(":")[0]
                                    tabState.tasks[i].tabs[j].title = arrLinks[j].split(":")[1]
                                }
                            }
                        }
                    }
                    rerenderTabstrip()
                    switchToTask(id)
                    if(arrLinks.length>0){
                        openURLFromsearchbar('', arrLinks[0].split(":")[0])
                    }
                }
            } catch (e) {
            }
            CT._openCollectionNOWClickTime = new Date() + 1
        }

    },
    goToCollectionID(id) {
        say.m('CT.goToCollectionID(id): ' + id)

        try {
            let index = CT.getIndexFromIdTaskId(id)
            if (index == 0) {
                switchToTask(tabState.tasks[index].id)
            } else {
                switchToTask(tabState.tasks[index - 1].id)
            }

            CT.render()
        } catch (e) {
            CT.render()
            taskOverlay.inputFocus = false
        }

    },
    getIndexFromIdTaskId(id) {
        say.m('CT.getIndexFromIdTaskId(id): ' + id)

        let index = ''

        for (let i = 0; i < tabState.tasks.length; i++) {
            console.log(tabState.tasks[i].id)
            if (tabState.tasks[i].id == id) {
                index = i
            }
        }

        console.log('id: ' + id, 'index: ' + index)
        return index
    },
    addClassEditing() {
        document.querySelector('.active-tab input').disabled = false
        document.querySelector('.active-tab input').select()
        document.querySelector('.active-tab').className += ' editing'
    },
    remoteClassEditing() {
        say.m('CT.remoteClassEditing()')

        try {
            if (document.querySelector('.active-tab ').className.indexOf("editing") != -1) {
                document.querySelector('.active-tab ').classList.remove("editing");
                CT.remoteClassEditing()
            }
        } catch (e) {
        }
    },
    getDataFromE(e) {
        say.m('CT.getDataFromE(e)' + e)

        if (e.target.type == 'text') {
            CT.taskId = e.target.parentElement.dataset.taskId
            CT.taskIndex = e.target.parentElement.dataset.index
        } else {
            CT.taskId = e.target.dataset.taskId
            CT.taskIndex = e.target.dataset.index
        }

        CT.tabId = tabState.tasks[CT.taskIndex].tabs[0].id

        CT.tab = document.querySelector('[data-tab="' + CT.taskIndex + '"]')
        CT.tabActive = document.querySelector('.active-tab.collection-tab')

        CT.prevTabIndex.push(CT.taskIndex) // history tabs

        tabState.selectedTask = tabState.tasks[CT.prevTabIndex[CT.prevTabIndex.length - 1]].id

    },
    selectFirstTabOnStart() {
        tabState.selectedTask = tabState.tasks[0].id
        switchToTask(tabState.selectedTask)
        sessionRestore.save()
    },
    loadTasks() {
        tasks.get().forEach(function (task, index) {
            var el = getTaskElement(task, index)
            taskContainer.appendChild(el)
            taskOverlay.dragula.containers.push(el.getElementsByClassName('task-tabs-container')[0])
        })
    },
    clickOnFirstCollection() {
        document.querySelector('[data-task-id="' + tasks.get()[0].id + ' "]').click()
    },
    add5() {
        say.m('CT.add5()')
        if (tabState.tasks.length < 5) {
            let id = tabState.selectedTask
            for (let i = tabState.tasks.length; i != 5; i++) {
                tasks.add()
            }
        }
    },
    add5tab() {
        say.m('CT.add5tab()')

        for (let i = 0; i < tabState.tasks.length; i++) {
            if (tabState.tasks[i].id == tabState.selectedTask) {
                for (let j = tabState.tasks[i].tabs.length; j < 5; j++) {
                    addTab(tabs.add({url: ''}, tabs[0]), {enterEditMode: false})
                }
            } else {
                if (tabState.tasks[i].tabs.length == 1 && tabState.tasks[i].tabs[0].url == 'duckduckgo.com') {

                    tabState.tasks[i].tabs[0].url = ''
                    tabState.tasks[i].tabs[0].title = ''
                }
            }
        }
    },
    addEmptyTabStyle() {
        say.m('CT.addEmptyTabStyle()')

        let tabViewContents = document.querySelectorAll('.tab-view-contents')
        for (let i = 0; i < tabViewContents.length; i++) {
            if (tabViewContents[i].querySelector('.title').innerText == '...' && !tabViewContents[i].classList.contains('addEmptyTabStyle')) {
                tabViewContents[i].className += " addEmptyTabStyle"
            } else if (tabViewContents[i].classList.contains('addEmptyTabStyle')) {
                tabViewContents[i].classList.remove('addEmptyTabStyle');
            }
        }
    },
    overviewTaskNameClickEnterE(e) {
        say.m('CT.overviewTaskNameClickEnterE()')

        let id = e.target.parentElement.parentElement.getAttribute('data-task')
        let eTarget = e.target
        let eVal = e.target.value
        if (e.which == 13) {
            CT.render()
            for (let i = 0; i < tasks.get().length; i++) {
                if (tasks.get()[i].id == id) {
                    if (i <= 5) {
                        document.querySelector(`[data-index="${i}"]`).click()
                    }
                }
            }
        }
    },
    overviewTaskNameClickE(e) {
        say.m('CT.overviewTaskNameClickE()')

        let id = e.target.parentElement.parentElement.getAttribute('data-task')
        for (let i = 0; i < tasks.get().length; i++) {
            if (tasks.get()[i].id == id) {
                if (i <= 5) {
                    CT.collectionTopClickOnCollectionTab(i)
                    CT.collectionLeftFocusOnCollectionTabInput(id)
                }
            }
        }
    },

    collectionTopClickOnCollectionTab(index) {
        document.querySelector(`[data-index="${index}"]`).click()
    },
    collectionTopRemoveBGSelectedAll() {
        let elems = document.querySelectorAll(".active-tab");
        for (var i = 0; i < elems.length; i++)
            elems[i].classList.remove('active-tab');
    },
    collectionTopAddBGSelected(index) {
        CT.collectionTopRemoveBGSelectedAll()
        document.querySelector(`[data-index="${index}"]`).classList.add('active-tab')
    },
    collectionTopAddBGSelectedById(id_) {
        CT.collectionTopRemoveBGSelectedAll()
        document.querySelector(`[data-task-id="${id_} "]`).classList.add('active-tab')
    },
    collectionLeftFocusOnCollectionTabInput(id) {
        document.querySelector(`[data-task="${id}"] input`).focus()
    },
    addCollectionTab() {
        say.m('CT.addCollectionTab()')

        // let thereIsCollection = false
        // for (let i = 0; i < tabState.tasks.length; i++) {
        //     if (tabState.tasks[i].id == tabState.selectedTask) {
        //         for (let j = 0; j < tabState.tasks[i].tabs.length; j++) {
        //             if (tabState.tasks[i].tabs[j].title == 'Collection') {
        //                 thereIsCollection = true
        //             }
        //
        //         }
        //         if (tabState.tasks[i].tabs.length == 2) {
        //             for (let j = 0; j < tabState.tasks[i].tabs.length; j++) {
        //                 if (tabState.tasks[i].tabs[j].url == 'duckduckgo.com') {
        //                     destroyTab(tabState.tasks[i].tabs[j].id)
        //                 }
        //
        //             }
        //         }
        //         // else if (tabState.tasks[i].tabs.length == 1) {
        //             // alert(tabState.tasks[i].tabs.length)
        //             // console.log('--------------------', tabState.tasks[i].tabs.length)
        //             // tabState.tasks[i].tabs[0].title = 'Collection'
        //             // tabState.tasks[i].tabs[0].url = 'file:///' + __dirname + '/pages/collection/index.html'
        //
        //             // navigate(tabState.tasks[i].tabs[0].id, 'file:///' + __dirname + '/pages/collection/index.html')
        //
        //         // }
        //     }
        // }
        // if (thereIsCollection == false && document.querySelector('.active-tab ').className.indexOf("editing") != -1) {
        //     addTab(tabs.add({
        //         url: 'file:///' + __dirname + '/pages/collection/index.html',
        //         title: 'Collection'
        //     }, tabs[0]), {enterEditMode: false})
        //     CT.addClassEditing()
        // }

    },

    render() {
        say.m('CT.render()')

        CT.add5tab()
        // CT.addEmptyTabStyle()

        if (CT.inputFocus == false) {
            let collectionTabsHTML = []
            for (let i = 0; i < tabState.tasks.length; i++) {
                let val = tabState.tasks[i].name
                if (val == null || val == 'null')
                    val = ''
                let title = `<input placeholder="●●●" type="text" class="collectionTabInput" data-id="${tabState.tasks[i].id}" value="${val}" disabled="true">` || `<input type="text" placeholder="●●●" class="collectionTabInput" data-id="${tabState.tasks[i].id}" value="${val}"  disabled="true"> <svg width="23.9px" height="5.6px">23.9 5.6 <use xlink:href="icons/svg/miniature-controls.svg#ellipsis-big"></use></svg>`
                collectionTabsHTML.push('
' + title + '
')
            }
            document.getElementById('collection-tabs').innerHTML = collectionTabsHTML.join('')
            // CT.addEmptyTabStyle()

            CT.renderOverlay()
            // CT.addEmptyTabStyle()

            eventEmitter.emit('render')

        }
    },
    renderOverlay() {
        say.m('CT.renderOverlay() ' + taskOverlay.inputFocus)

        eventEmitter.emit('renderOverlay')

        if (taskOverlay.inputFocus) {
            if (document.querySelector('#task-overlay').getAttribute('hidden') == null)
                taskOverlay.show()
        }

        eventEmitter.emit('render')

    }

}
CT.start()

<|endoftext|>


<commit_before>var max = require('./');
var test = require('tape');
var polygon = require('turf-polygon');
var point = require('turf-point');
var featurecollection = require('turf-featurecollection');

test('max', function(t){
  var poly1 = polygon([[[0,0],[10,0],[10,10], [0,10]]]);
  var poly2 = polygon([[[10,0],[20,10],[20,20], [20,0]]]);
  var polyFC = featurecollection([poly1, poly2]);
  var pt1 = point(5,5, {population: 200});
  var pt2 = point(1,3, {population: 600});
  var pt3 = point(14,2, {population: 100});
  var pt4 = point(13,1, {population: 200});
  var pt5 = point(19,7, {population: 300});
  var ptFC = featurecollection([pt1, pt2, pt3, pt4, pt5]);

  var maxed = max(polyFC, ptFC, 'population', 'pop_max');

  t.equal(maxed.features[0].geometry.type, 'Polygon');
  t.equal(maxed.features[0].properties.pop_max, 600);
  t.equal(maxed.features[1].properties.pop_max, 300);

  t.end();
})<commit_msg>Update for turf-point<commit_after>var max = require('./');
var test = require('tape');
var polygon = require('turf-polygon');
var point = require('turf-point');
var featurecollection = require('turf-featurecollection');

test('max', function(t){
  var poly1 = polygon([[[0,0],[10,0],[10,10], [0,10]]]);
  var poly2 = polygon([[[10,0],[20,10],[20,20], [20,0]]]);
  var polyFC = featurecollection([poly1, poly2]);
  var pt1 = point([5,5], {population: 200});
  var pt2 = point([1,3], {population: 600});
  var pt3 = point([14,2], {population: 100});
  var pt4 = point([13,1], {population: 200});
  var pt5 = point([19,7], {population: 300});
  var ptFC = featurecollection([pt1, pt2, pt3, pt4, pt5]);

  var maxed = max(polyFC, ptFC, 'population', 'pop_max');

  t.equal(maxed.features[0].geometry.type, 'Polygon');
  t.equal(maxed.features[0].properties.pop_max, 600);
  t.equal(maxed.features[1].properties.pop_max, 300);

  t.end();
})
<|endoftext|>


<commit_before>import React from 'react';
import lbry from '../lbry.js';
import FormField from './form.js';
import Modal from './modal.js';
import {Menu, MenuItem} from './menu.js';
import {Icon, ToolTip} from './common.js';

export let Link = React.createClass({
  propTypes: {
    label: React.PropTypes.string,
    icon: React.PropTypes.string,
    button: React.PropTypes.string,
    badge: React.PropTypes.string,
    hidden: React.PropTypes.bool,
  },
  getDefaultProps: function() {
    return {
      hidden: false,
      disabled: false,
    };
  },
  handleClick: function() {
    if (this.props.onClick) {
      this.props.onClick();
    }
  },
  render: function() {
    if (this.props.hidden) {
      return null;
    }

    const className = (this.props.className || '') +
      (this.props.button ? ' button-block button-' + this.props.button : '') +
      (!this.props.className && !this.props.button ? 'button-text' : '') +
      (this.props.disabled ? ' disabled' : '');

    let content;
    if (this.props.children) { // Custom content
      content = this.props.children;
    } else {
      content = (

          {'icon' in this.props
            ? <Icon icon={this.props.icon} fixed={true} />
            : null}
           {this.props.label}
          {'badge' in this.props
            ? {this.props.badge}
            : null}

      );
    }

    return (

         {content}

    );
  }
});

var linkContainerStyle = {
  position: 'relative',
};

export let ToolTipLink = React.createClass({
  getInitialState: function() {
    return {
      showTooltip: false,
    };
  },
  handleClick: function() {
    if (this.props.tooltip) {
      this.setState({
        showTooltip: !this.state.showTooltip,
      });
    }
    if (this.props.onClick) {
      this.props.onClick();
    }
  },
  handleTooltipMouseOut: function() {
    this.setState({
      showTooltip: false,
    });
  },
  render: function() {
    var href = this.props.href ? this.props.href : 'javascript:;',
      icon = this.props.icon ? <Icon icon={this.props.icon} />  : '',
      className = this.props.className +
        (this.props.button ? ' button-block button-' + this.props.button : '') +
        (this.props.hidden ? ' hidden' : '') +
        (this.props.disabled ? ' disabled' : '');

    return (

          {this.props.icon ? icon : '' }
          {this.props.label}

        {(!this.props.tooltip ? null :
          <ToolTip open={this.state.showTooltip} onMouseOut={this.handleTooltipMouseOut}>
            {this.props.tooltip}
          </ToolTip>
        )}

    );
  }
});

export let DropDown = React.createClass({
  propTypes: {
    onCaretClick: React.PropTypes.func,
  },
  handleCaretClicked: function(event) {
    /**
     * The menu handles caret clicks via a window event listener, so we just need to prevent clicks
     * on the caret from bubbling up to the link
     */
    this.setState({
      menuOpen: !this.state.menuOpen,
    });
    event.stopPropagation();
    return false;
  },
  closeMenu: function(event) {
    this.setState({
      menuOpen: false,
    });
  },
  getInitialState: function() {
    return {
      menuOpen: false,
    };
  },
  render: function() {
    const {onCaretClick, ...other} = this.props;
    return (

        <Link {...other}>
          {this.props.label}
          <Icon icon="icon-caret-down" fixed={true} onClick={this.handleCaretClicked} />
        </Link>
        {this.state.menuOpen
          ? <Menu onClickOut={this.closeMenu}>
              {this.props.children}
            </Menu>
          : null}

    );
  }
});

export let DownloadLink = React.createClass({
  propTypes: {
    type: React.PropTypes.string,
    streamName: React.PropTypes.string,
    sdHash: React.PropTypes.string,
    metadata: React.PropTypes.object,
    label: React.PropTypes.string,
    button: React.PropTypes.string,
    state: React.PropTypes.oneOf(['not-started', 'downloading', 'done']),
    progress: React.PropTypes.number,
    path: React.PropTypes.string,
    hidden: React.PropTypes.bool,
    deleteChecked: React.PropTypes.bool,
  },
  tryDownload: function() {
    this.setState({
      attemptingDownload: true,
    });
    lbry.getCostInfoForName(this.props.streamName, ({cost}) => {
      lbry.getBalance((balance) => {
        if (cost > balance) {
          this.setState({
            modal: 'notEnoughCredits',
            attemptingDownload: false,
          });
        } else {
          lbry.getStream(this.props.streamName, (streamInfo) => {
            if (streamInfo === null || typeof streamInfo !== 'object') {
              this.setState({
                modal: 'timedOut',
                attemptingDownload: false,
              });
            } else {
              this.setState({
                filePath: streamInfo.path,
                attemptingDownload: false,
              });
            }
          });
        }
      });
    });
  },
  openMenu: function() {
    this.setState({
      menuOpen: !this.state.menuOpen,
    });
  },
  handleDeleteCheckboxClicked: function(event) {
    this.setState({
      deleteChecked: event.target.checked,
    });
  },
  handleRevealClicked: function() {
    lbry.revealFile(this.props.path);
  },
  handleRemoveClicked: function() {
    this.setState({
      modal: 'confirmRemove',
    });
  },
  handleRemoveConfirmed: function() {
    lbry.deleteFile(this.props.sdHash || this.props.streamName, this.state.deleteChecked);
    this.setState({
      modal: null,
    });
  },
  getDefaultProps: function() {
    return {
      state: 'not-started',
    }
  },
  getInitialState: function() {
    return {
      filePath: null,
      modal: null,
      menuOpen: false,
      deleteChecked: false,
      attemptingDownload: false,
    }
  },
  closeModal: function() {
    this.setState({
      modal: null,
    })
  },
  handleClick: function() {
    if (this.props.state == 'not-started') {
      this.tryDownload();
    } else if (this.props.state == 'done') {
      lbry.revealFile(this.props.path);
    }
  },
  render: function() {
    const openInFolderMessage = window.navigator.platform.startsWith('Mac') ? 'Open in Finder' : 'Open in Folder';

    const dropDownItems = [
      <MenuItem onClick={this.handleRevealClicked} label={openInFolderMessage} />,
      <MenuItem onClick={this.handleRemoveClicked} label="Remove..." />,
    ];

    let linkBlock;
    if (this.state.attemptingDownload) {
      linkBlock = <Link button="text" className="button-download button-download--bg"
                        label="Connecting..." icon="icon-download" />
    } else if (this.props.state == 'downloading') {
      const label = `${parseInt(this.props.progress * 100)}% complete`;
      linkBlock = (

          <DropDown button="download" className="button-download--bg" label={label} icon="icon-download"
                    onClick={this.handleClick}>
            {dropDownItems}
          </DropDown>
          <DropDown button="download" className="button-download--fg" label={label} icon="icon-download"
                    onClick={this.handleClick} style={{width: `${this.props.progress * 100}%`}}>
            {dropDownItems}
          </DropDown>

      );
    } else if (this.props.state == 'not-started') {
      linkBlock = (
        <Link button="text" label="Download" icon="icon-download" onClick={this.handleClick} />
      );
    } else if (this.props.state == 'done') {
      linkBlock = (
        <DropDown button="alt" label="Open" onClick={this.handleClick} onCaretClick={this.openMenu}>
          {dropDownItems}
        </DropDown>
      );
    } else {
      throw new Error(`Unknown download state ${this.props.state} passed to DownloadLink`);
    }

    return (

        <Modal isOpen={this.state.modal == 'notEnoughCredits'} contentLabel="Not enough credits"
               onConfirmed={this.closeModal}>
          You don't have enough LBRY credits to pay for this stream.
        </Modal>
        <Modal isOpen={this.state.modal == 'timedOut'} contentLabel="Download failed"
               onConfirmed={this.closeModal}>
          LBRY was unable to download the stream lbry://{this.props.streamName}.
        </Modal>
        <Modal isOpen={this.state.modal == 'confirmRemove'} type="confirm" confirmButtonLabel="Remove"
               onConfirmed={this.handleRemoveConfirmed} onAborted={this.closeModal}>

Are you sure you'd like to remove {this.props.metadata.title} from LBRY?

          <FormField type="checkbox" checked={this.state.deleteChecked} onClick={this.handleDeleteCheckboxClicked} /> Delete this file from my computer
        </Modal>

    );
  }
});

export let WatchLink = React.createClass({
  propTypes: {
    type: React.PropTypes.string,
    streamName: React.PropTypes.string,
    label: React.PropTypes.string,
    button: React.PropTypes.string,
    hidden: React.PropTypes.bool,
  },
  handleClick: function() {
    this.setState({
      loading: true,
    })
    lbry.getCostInfoForName(this.props.streamName, ({cost}) => {
      lbry.getBalance((balance) => {
        if (cost > balance) {
          this.setState({
            modal: 'notEnoughCredits',
            loading: false,
          });
        } else {
          window.location = '?watch=' + this.props.streamName;
        }
      });
    });
  },
  getInitialState: function() {
    return {
      modal: null,
      loading: false,
    };
  },
  closeModal: function() {
    this.setState({
      modal: null,
    });
  },
  getDefaultProps: function() {
    return {
      icon: 'icon-play',
      label: 'Watch',
    }
  },
  render: function() {
    return (

        <Link button={this.props.button} hidden={this.props.hidden} style={this.props.style}
              disabled={this.state.loading} label={this.props.label} icon={this.props.icon}
              onClick={this.handleClick} />
        <Modal isOpen={this.state.modal == 'notEnoughCredits'} contentLabel="Not enough credits"
               onConfirmed={this.closeModal}>
          You don't have enough LBRY credits to pay for this stream.
        </Modal>

    );
  }
});
<commit_msg>Add keys to DownloadLink menu items<commit_after>import React from 'react';
import lbry from '../lbry.js';
import FormField from './form.js';
import Modal from './modal.js';
import {Menu, MenuItem} from './menu.js';
import {Icon, ToolTip} from './common.js';

export let Link = React.createClass({
  propTypes: {
    label: React.PropTypes.string,
    icon: React.PropTypes.string,
    button: React.PropTypes.string,
    badge: React.PropTypes.string,
    hidden: React.PropTypes.bool,
  },
  getDefaultProps: function() {
    return {
      hidden: false,
      disabled: false,
    };
  },
  handleClick: function() {
    if (this.props.onClick) {
      this.props.onClick();
    }
  },
  render: function() {
    if (this.props.hidden) {
      return null;
    }

    const className = (this.props.className || '') +
      (this.props.button ? ' button-block button-' + this.props.button : '') +
      (!this.props.className && !this.props.button ? 'button-text' : '') +
      (this.props.disabled ? ' disabled' : '');

    let content;
    if (this.props.children) { // Custom content
      content = this.props.children;
    } else {
      content = (

          {'icon' in this.props
            ? <Icon icon={this.props.icon} fixed={true} />
            : null}
           {this.props.label}
          {'badge' in this.props
            ? {this.props.badge}
            : null}

      );
    }

    return (

         {content}

    );
  }
});

var linkContainerStyle = {
  position: 'relative',
};

export let ToolTipLink = React.createClass({
  getInitialState: function() {
    return {
      showTooltip: false,
    };
  },
  handleClick: function() {
    if (this.props.tooltip) {
      this.setState({
        showTooltip: !this.state.showTooltip,
      });
    }
    if (this.props.onClick) {
      this.props.onClick();
    }
  },
  handleTooltipMouseOut: function() {
    this.setState({
      showTooltip: false,
    });
  },
  render: function() {
    var href = this.props.href ? this.props.href : 'javascript:;',
      icon = this.props.icon ? <Icon icon={this.props.icon} />  : '',
      className = this.props.className +
        (this.props.button ? ' button-block button-' + this.props.button : '') +
        (this.props.hidden ? ' hidden' : '') +
        (this.props.disabled ? ' disabled' : '');

    return (

          {this.props.icon ? icon : '' }
          {this.props.label}

        {(!this.props.tooltip ? null :
          <ToolTip open={this.state.showTooltip} onMouseOut={this.handleTooltipMouseOut}>
            {this.props.tooltip}
          </ToolTip>
        )}

    );
  }
});

export let DropDown = React.createClass({
  propTypes: {
    onCaretClick: React.PropTypes.func,
  },
  handleCaretClicked: function(event) {
    /**
     * The menu handles caret clicks via a window event listener, so we just need to prevent clicks
     * on the caret from bubbling up to the link
     */
    this.setState({
      menuOpen: !this.state.menuOpen,
    });
    event.stopPropagation();
    return false;
  },
  closeMenu: function(event) {
    this.setState({
      menuOpen: false,
    });
  },
  getInitialState: function() {
    return {
      menuOpen: false,
    };
  },
  render: function() {
    const {onCaretClick, ...other} = this.props;
    return (

        <Link {...other}>
          {this.props.label}
          <Icon icon="icon-caret-down" fixed={true} onClick={this.handleCaretClicked} />
        </Link>
        {this.state.menuOpen
          ? <Menu onClickOut={this.closeMenu}>
              {this.props.children}
            </Menu>
          : null}

    );
  }
});

export let DownloadLink = React.createClass({
  propTypes: {
    type: React.PropTypes.string,
    streamName: React.PropTypes.string,
    sdHash: React.PropTypes.string,
    metadata: React.PropTypes.object,
    label: React.PropTypes.string,
    button: React.PropTypes.string,
    state: React.PropTypes.oneOf(['not-started', 'downloading', 'done']),
    progress: React.PropTypes.number,
    path: React.PropTypes.string,
    hidden: React.PropTypes.bool,
    deleteChecked: React.PropTypes.bool,
  },
  tryDownload: function() {
    this.setState({
      attemptingDownload: true,
    });
    lbry.getCostInfoForName(this.props.streamName, ({cost}) => {
      lbry.getBalance((balance) => {
        if (cost > balance) {
          this.setState({
            modal: 'notEnoughCredits',
            attemptingDownload: false,
          });
        } else {
          lbry.getStream(this.props.streamName, (streamInfo) => {
            if (streamInfo === null || typeof streamInfo !== 'object') {
              this.setState({
                modal: 'timedOut',
                attemptingDownload: false,
              });
            } else {
              this.setState({
                filePath: streamInfo.path,
                attemptingDownload: false,
              });
            }
          });
        }
      });
    });
  },
  openMenu: function() {
    this.setState({
      menuOpen: !this.state.menuOpen,
    });
  },
  handleDeleteCheckboxClicked: function(event) {
    this.setState({
      deleteChecked: event.target.checked,
    });
  },
  handleRevealClicked: function() {
    lbry.revealFile(this.props.path);
  },
  handleRemoveClicked: function() {
    this.setState({
      modal: 'confirmRemove',
    });
  },
  handleRemoveConfirmed: function() {
    lbry.deleteFile(this.props.sdHash || this.props.streamName, this.state.deleteChecked);
    this.setState({
      modal: null,
    });
  },
  getDefaultProps: function() {
    return {
      state: 'not-started',
    }
  },
  getInitialState: function() {
    return {
      filePath: null,
      modal: null,
      menuOpen: false,
      deleteChecked: false,
      attemptingDownload: false,
    }
  },
  closeModal: function() {
    this.setState({
      modal: null,
    })
  },
  handleClick: function() {
    if (this.props.state == 'not-started') {
      this.tryDownload();
    } else if (this.props.state == 'done') {
      lbry.revealFile(this.props.path);
    }
  },
  render: function() {
    const openInFolderMessage = window.navigator.platform.startsWith('Mac') ? 'Open in Finder' : 'Open in Folder';

    const dropDownItems = [
      <MenuItem key={0} onClick={this.handleRevealClicked} label={openInFolderMessage} />,
      <MenuItem key={1} onClick={this.handleRemoveClicked} label="Remove..." />,
    ];

    let linkBlock;
    if (this.state.attemptingDownload) {
      linkBlock = <Link button="text" className="button-download button-download--bg"
                        label="Connecting..." icon="icon-download" />
    } else if (this.props.state == 'downloading') {
      const label = `${parseInt(this.props.progress * 100)}% complete`;
      linkBlock = (

          <DropDown button="download" className="button-download--bg" label={label} icon="icon-download"
                    onClick={this.handleClick}>
            {dropDownItems}
          </DropDown>
          <DropDown button="download" className="button-download--fg" label={label} icon="icon-download"
                    onClick={this.handleClick} style={{width: `${this.props.progress * 100}%`}}>
            {dropDownItems}
          </DropDown>

      );
    } else if (this.props.state == 'not-started') {
      linkBlock = (
        <Link button="text" label="Download" icon="icon-download" onClick={this.handleClick} />
      );
    } else if (this.props.state == 'done') {
      linkBlock = (
        <DropDown button="alt" label="Open" onClick={this.handleClick} onCaretClick={this.openMenu}>
          {dropDownItems}
        </DropDown>
      );
    } else {
      throw new Error(`Unknown download state ${this.props.state} passed to DownloadLink`);
    }

    return (

        <Modal isOpen={this.state.modal == 'notEnoughCredits'} contentLabel="Not enough credits"
               onConfirmed={this.closeModal}>
          You don't have enough LBRY credits to pay for this stream.
        </Modal>
        <Modal isOpen={this.state.modal == 'timedOut'} contentLabel="Download failed"
               onConfirmed={this.closeModal}>
          LBRY was unable to download the stream lbry://{this.props.streamName}.
        </Modal>
        <Modal isOpen={this.state.modal == 'confirmRemove'} type="confirm" confirmButtonLabel="Remove"
               onConfirmed={this.handleRemoveConfirmed} onAborted={this.closeModal}>

Are you sure you'd like to remove {this.props.metadata.title} from LBRY?

          <FormField type="checkbox" checked={this.state.deleteChecked} onClick={this.handleDeleteCheckboxClicked} /> Delete this file from my computer
        </Modal>

    );
  }
});

export let WatchLink = React.createClass({
  propTypes: {
    type: React.PropTypes.string,
    streamName: React.PropTypes.string,
    label: React.PropTypes.string,
    button: React.PropTypes.string,
    hidden: React.PropTypes.bool,
  },
  handleClick: function() {
    this.setState({
      loading: true,
    })
    lbry.getCostInfoForName(this.props.streamName, ({cost}) => {
      lbry.getBalance((balance) => {
        if (cost > balance) {
          this.setState({
            modal: 'notEnoughCredits',
            loading: false,
          });
        } else {
          window.location = '?watch=' + this.props.streamName;
        }
      });
    });
  },
  getInitialState: function() {
    return {
      modal: null,
      loading: false,
    };
  },
  closeModal: function() {
    this.setState({
      modal: null,
    });
  },
  getDefaultProps: function() {
    return {
      icon: 'icon-play',
      label: 'Watch',
    }
  },
  render: function() {
    return (

        <Link button={this.props.button} hidden={this.props.hidden} style={this.props.style}
              disabled={this.state.loading} label={this.props.label} icon={this.props.icon}
              onClick={this.handleClick} />
        <Modal isOpen={this.state.modal == 'notEnoughCredits'} contentLabel="Not enough credits"
               onConfirmed={this.closeModal}>
          You don't have enough LBRY credits to pay for this stream.
        </Modal>

    );
  }
});
<|endoftext|>


<commit_before>import test from 'ava';
import parser from './parser';

test('It should sort modules correctly', t => {
	const modules = [
		{
			short_name: 'BWL III',
			status: 'FAILED',
			link: 'www.vorlesungen.uzh.ch/HS16/suche/sm-50018688.modveranst.html'
		},
		{
			short_name: 'Asset Pricing',
			status: 'PASSED',
			link: 'www.vorlesungen.uzh.ch/HS16/suche/sm-50018689.modveranst.html'
		}
	];

	const output = [
		{
			short_name: 'Asset Pricing',
			status: 'PASSED',
			link: 'www.vorlesungen.uzh.ch/HS16/suche/sm-50018689.modveranst.html#0'
		},
		{
			short_name: 'BWL III',
			status: 'FAILED',
			link: 'www.vorlesungen.uzh.ch/HS16/suche/sm-50018688.modveranst.html#1'
		}
	];

	t.deepEqual(output, parser.filterDuplicates(modules));
});
<commit_msg>Define new test<commit_after>import test from 'ava';
import parser from './parser';

test('It should sort modules correctly', t => {
	const modules = [
		{
			short_name: 'BWL III',
			status: 'FAILED',
			link: 'www.vorlesungen.uzh.ch/HS16/suche/sm-50018688.modveranst.html'
		},
		{
			short_name: 'Asset Pricing',
			status: 'PASSED',
			link: 'www.vorlesungen.uzh.ch/HS16/suche/sm-50018689.modveranst.html'
		}
	];

	const output = [
		{
			short_name: 'Asset Pricing',
			status: 'PASSED',
			link: 'www.vorlesungen.uzh.ch/HS16/suche/sm-50018689.modveranst.html#0'
		},
		{
			short_name: 'BWL III',
			status: 'FAILED',
			link: 'www.vorlesungen.uzh.ch/HS16/suche/sm-50018688.modveranst.html#1'
		}
	];

	t.deepEqual(output, parser.filterDuplicates(modules));
});

test('It should sort semesters reverse-chronologically', t => {
	const older = {
		link: 'http://www.vorlesungen.uzh.ch/FS09/lehrangebot/fak-50000003/sc-50427948/cga-50427948010/cg-50427949/sm-50345595/person-1092257.details.html'
	};
	const newer = {
		link: 'http://www.vorlesungen.uzh.ch/FS16/lehrangebot/fak-50000003/sc-50427948/cga-50427948010/cg-50427949/sm-50345595/person-1092257.details.html'
	};

	t.deepEqual(parser.groupBySemester([newer, older]), [{semester: 'FS16', credits: [newer]}, {semester: 'FS09', credits: [older]}]);
});
<|endoftext|>


<commit_before>#! /usr/bin/env node

const shell = require('shelljs');

const docsDir = './docs/gaiden-css';
const sourceDocsDir = './docs/demo/gaiden-css/scss';
const sourceDir = './src/scss';
const minifiedDocsFile = `${docsDir}/ninja-demo.css`;

const timestamp = new Date().getTime();

const options = {
  sass: ` --include-path ${sourceDocsDir} \
    --include-path ${sourceDir} \
    --output-style expanded \
    --sourceComments true \
    -o ${docsDir} \
    --recursive `
}

shell.exec('git checkout -B gh-pages');
shell.exec('git pull origin gh-pages');

shell.exec(`node-sass ${sourceDocsDir} ${options.sass} ${minifiedDocsFile}`);
shell.exec(`documentjs`);

shell.cp('./dist/gaiden.min.css', './');

shell.cp('-R', `${docsDir}/`, './');

shell.ls('./docs/demo/*.html').forEach(function(file) {
  shell.sed('-i', 'docs\/demo\/', 'demo', file);
  shell.sed('-i', '\/gaiden-css\/gaiden.css', '\/gaiden.css', file);
});

shell.mkdir('./demo');
shell.mv('-fn', './docs/demo/*', './demo/');

shell.exec('$GAIDEN_LAST_TAG=$(git describe)')
shell.exec('git add .');
shell.exec(`git commit -m '${timestamp}: Updating docs $GAIDEN_LAST_TAG'`);
shell.exec('git push origin gh-pages');
shell.exec('git checkout -');
<commit_msg>Using --no-commit on pull from gh-pages<commit_after>#! /usr/bin/env node

const shell = require('shelljs');

const docsDir = './docs/gaiden-css';
const sourceDocsDir = './docs/demo/gaiden-css/scss';
const sourceDir = './src/scss';
const minifiedDocsFile = `${docsDir}/ninja-demo.css`;

const timestamp = new Date().getTime();

const options = {
  sass: ` --include-path ${sourceDocsDir} \
    --include-path ${sourceDir} \
    --output-style expanded \
    --sourceComments true \
    -o ${docsDir} \
    --recursive `
}

shell.exec('git checkout -B gh-pages');
shell.exec('git pull origin gh-pages --no-commit');

shell.exec(`node-sass ${sourceDocsDir} ${options.sass} ${minifiedDocsFile}`);
shell.exec(`documentjs`);

shell.cp('./dist/gaiden.min.css', './');

shell.cp('-R', `${docsDir}/`, './');

shell.ls('./docs/demo/*.html').forEach(function(file) {
  shell.sed('-i', 'docs\/demo\/', 'demo', file);
  shell.sed('-i', '\/gaiden-css\/gaiden.css', '\/gaiden.css', file);
});

shell.mkdir('./demo');
shell.mv('-fn', './docs/demo/*', './demo/');

shell.exec('$GAIDEN_LAST_TAG=$(git describe)')
shell.exec('git add .');
shell.exec(`git commit -m '${timestamp}: Updating docs $GAIDEN_LAST_TAG'`);
shell.exec('git push origin gh-pages');
shell.exec('git checkout -');
<|endoftext|>


<commit_before>// Columns

// TODO: Make private function

var createCol = function(obj) {
  var output = '';

  $.each(obj, function(v,k) {
    var temp = ''
    var contents = $(this).html();
    var colClass = 'columns ' + $(this).attr('class');

    if (v !== obj.length - 1) {
      temp = ''
              +'
'
              +'
'
              + contents +'

	';
    } else {
      temp = ''
              +'
'
              +'
'
              + contents +'

	';
    }

    output += temp;
  });

  return output;
};
<commit_msg>Added 'expander' class into columns.<commit_after>// Columns

// TODO: Make private function

var createCol = function(obj) {
  var output = '';

  $.each(obj, function(v,k) {
    var temp = ''
    var contents = $(this).html();
    var colClass = 'columns ' + $(this).attr('class');

    if (v !== obj.length - 1) {
      temp = ''
              +'
'
              +'
'
              + contents +'

	';
    } else {
      temp = ''
              +'
'
              +'
'
              + contents +'

	';
    }

    output += temp;
  });

  return output;
};
<|endoftext|>


<commit_before>'use strict'

var test = require('tape')
var C = require('./constants')
var ipp = require('./')

test('encodingLength', function (t) {
  var types = ['request', 'response']

  types.forEach(function (type) {
    t.test(type + ' minimal', function (t) {
      var len = ipp[type].encodingLength({})
      t.deepEqual(len, 9)
      t.end()
    })

    test(type + ' groups', function (t) {
      var date = new Date(2015, 11, 1, 1, 23, 45, 678)
      var obj = { // version + statusCode + operationId/requestId: +8
        groups: [
          { tag: 0, attributes: [ // +1 (9)
            { tag: C.KEYWORD, name: 'string', value: 'foo' }, // +1+2+6+2+3=14 (23)
            { tag: C.KEYWORD, name: 'array', value: ['foo', 'bar'] }, // +1+2+5+2+3+1+2+0+2+3=21 (44)
            { tag: C.BOOLEAN, name: 'bool', value: true }, // +1+2+4+2+1=10 (54)
            { tag: C.ENUM, name: 'enum', value: 1 } // +1+2+4+2+4=13 (67)
          ] },
          { tag: 1, attributes: [ // +1 (68)
            { tag: C.KEYWORD, name: 'string', value: ['foo'] }, // +1+2+6+2+3=14 (82)
            { tag: C.TEXT_WITH_LANG, name: 'text-with-language', value: { lang: 'fr-CA', value: 'fou' } }, // +1+2+18+2+2+5+2+3=35 (117)
            { tag: C.DATE_TIME, name: 'date-time', value: date } // +1+2+9+2+11=25 (142)
          ] }
        ]
      } // end tag: +1 (143)
      var len = ipp[type].encodingLength(obj)
      t.deepEqual(len, 143)
      t.end()
    })

    test(type + ' data', function (t) {
      var obj = { data: new Buffer('foo') }
      var len = ipp[type].encodingLength(obj)
      t.deepEqual(len, 12)
      t.end()
    })

    test(type + ' data + groups', function (t) {
      var obj = { // version + statusCode + operationId/requestId: +8
        groups: [
          { tag: 1, attributes: [ // +1 (9)
            { tag: C.KEYWORD, name: 'string', value: 'foo' } // +1+2+6+2+3=14 (23)
          ] }
        ],
        data: new Buffer('foo') // +3 (26)
      } // end tag: +1 (27)
      var len = ipp[type].encodingLength(obj)
      t.deepEqual(len, 27)
      t.end()
    })
  })
})

test('encode', function (t) {
  t.test('request', function (t) {
    t.test('minimal', function (t) {
      var obj = {
        operationId: C.PRINT_JOB,
        requestId: 42
      }
      var encoded = ipp.request.encode(obj)
      var expected = new Buffer('010100020000002a03', 'hex')
      t.deepEqual(encoded, expected)
      t.end()
    })
  })

  t.test('response', function (t) {
    t.test('minimal', function (t) {
      var obj = {
        statusCode: C.SERVER_ERROR_VERSION_NOT_SUPPORTED,
        requestId: 42
      }
      var encoded = ipp.response.encode(obj)
      var expected = new Buffer('010105030000002a03', 'hex')
      t.deepEqual(encoded, expected)
      t.end()
    })

    t.test('custom version', function (t) {
      var obj = {
        version: { major: 2, minor: 0 },
        statusCode: C.SUCCESSFUL_OK,
        requestId: 42
      }
      var encoded = ipp.response.encode(obj)
      var expected = new Buffer('020000000000002a03', 'hex')
      t.deepEqual(encoded, expected)
      t.end()
    })

    test('groups', function (t) {
      var date = new Date(2015, 11, 1, 1, 23, 45, 678)
      var obj = {
        statusCode: C.SUCCESSFUL_OK,
        requestId: 42,
        groups: [
          { tag: C.OPERATION_ATTRIBUTES_TAG, attributes: [
            { tag: C.KEYWORD, name: 'string', value: 'foo' },
            { tag: C.KEYWORD, name: 'array', value: ['foo', 'bar'] },
            { tag: C.BOOLEAN, name: 'bool', value: true },
            { tag: C.ENUM, name: 'enum', value: 42 }
          ] },
          { tag: C.JOB_ATTRIBUTES_TAG, attributes: [
            { tag: C.KEYWORD, name: 'string', value: ['foo'] },
            { tag: C.NAME_WITH_LANG, name: 'name-with-language', value: { lang: 'fr-CA', value: 'fou' } },
            { tag: C.DATE_TIME, name: 'date-time', value: date }
          ] }
        ]
      }
      var encoded = ipp.response.encode(obj)
      var expected = new Buffer(
        '0101' + // version
        '0000' + // statusCode
        '0000002a' + // requestId
        '01' + // delimiter tag
          '44' + // value tag
            '0006' + // name length
            '737472696e67' + // name
            '0003' + // value length
            '666f6f' + // value
          '44' + // value tag
            '0005' + // name length
            '6172726179' + // name
            '0003' + // value length
            '666f6f' + // value
          '44' + // value tag
            '0000' + // name length
            '' + // name
            '0003' + // value length
            '626172' + // value
          '22' + // value tag
            '0004' + // name length
            '626f6f6c' + // name
            '0001' + // value length
            '01' + // value
          '23' + // value tag
            '0004' + // name length
            '656e756d' + // name
            '0004' + // value length
            '0000002a' + // value
        '02' + // delimiter tag
          '44' + // value tag
            '0006' + // name length
            '737472696e67' + // name
            '0003' + // value length
            '666f6f' + // value
          '36' + // value tag
            '0012' + // name length
            '6e616d652d776974682d6c616e6775616765' + // name
            '000c' + // value length
            '0005' + // sub-value length
            '66722d4341' + // sub-value
            '0003' + // sub-value length
            '666f75' + // name
          '31' + // value tag
            '0009' + // name length
            '646174652d74696d65' + // name
            '000b' + // value length
            '07df0c0101172d062d0500' + // value
        '03', // end of attributes tag
        'hex')
      t.deepEqual(encoded, expected)
      t.end()
    })

    test('data', function (t) {
      var obj = {
        statusCode: C.SUCCESSFUL_OK, // +2 (4)
        requestId: 42, // +4 (8)
        data: new Buffer('foo')
      }
      var encoded = ipp.response.encode(obj)
      var expected = new Buffer(
        '0101' + // version
        '0000' + // statusCode
        '0000002a' + // requestId
        '03' + // end of attributes tag
        '666f6f', // data
        'hex')
      t.deepEqual(encoded, expected)
      t.end()
    })

    test('data + groups', function (t) {
      var obj = { // version: 2
        statusCode: C.SUCCESSFUL_OK, // +2 (4)
        requestId: 42, // +4 (8)
        groups: [
          { tag: C.JOB_ATTRIBUTES_TAG, attributes: [ // +1 (64)
            { tag: C.KEYWORD, name: 'string', value: 'foo' } // +1+2+6+2+3=14 (78)
          ] }
        ],
        data: new Buffer('foo')
      } // end tag: +1 (79)
      var encoded = ipp.response.encode(obj)
      var expected = new Buffer(
        '0101' + // version
        '0000' + // statusCode
        '0000002a' + // requestId
        '02' + // delimiter tag
          '44' + // value tag
            '0006' + // name length
            '737472696e67' + // name
            '0003' + // value length
            '666f6f' + // value
        '03' + // end of attributes tag
        '666f6f', // data
        'hex')
      t.deepEqual(encoded, expected)
      t.end()
    })
  })
})

test('decode', function (t) {
  t.test('request', function (t) {
    t.test('minimal', function (t) {
      var data = new Buffer('0101000a0000002a03', 'hex')
      var expected = {
        version: { major: 1, minor: 1 },
        operationId: 10,
        requestId: 42,
        groups: [],
        data: new Buffer(0)
      }
      var decoded = ipp.request.decode(data)
      t.deepEqual(decoded, expected)
      t.end()
    })

    t.test('truncated', function (t) {
      var data = new Buffer('0101000a0000002a', 'hex')
      t.throws(function () {
        ipp.request.decode(data)
      })
      t.end()
    })
  })
})

test('encode -> decode', function (t) {
  var encodeDate = new Date(2015, 11, 1, 1, 23, 45, 678)
  var decodeDate = new Date(2015, 11, 1, 1, 23, 45, 600)
  var obj = {
    version: { major: 1, minor: 0 },
    statusCode: C.SUCCESSFUL_OK,
    requestId: 42,
    groups: [
      { tag: C.OPERATION_ATTRIBUTES_TAG, attributes: [
        { tag: C.KEYWORD, name: 'string', value: ['foo'] },
        { tag: C.KEYWORD, name: 'array', value: ['foo', 'bar'] },
        { tag: C.BOOLEAN, name: 'bool', value: [true] },
        { tag: C.ENUM, name: 'enum', value: [42] }
      ] },
      { tag: C.JOB_ATTRIBUTES_TAG, attributes: [
        { tag: C.KEYWORD, name: 'string', value: ['foo'] },
        { tag: C.DATE_TIME, name: 'date-time', value: [encodeDate] }
      ] }
    ],
    data: new Buffer('foo')
  }
  var encoded = ipp.response.encode(obj)
  obj.groups[1].attributes[1].value[0] = decodeDate
  var decoded = ipp.response.decode(encoded)
  t.deepEqual(decoded, obj)
  t.end()
})
<commit_msg>Fix tests<commit_after>'use strict'

var test = require('tape')
var C = require('./constants')
var ipp = require('./')

test('encodingLength', function (t) {
  var types = ['request', 'response']

  types.forEach(function (type) {
    t.test(type + ' minimal', function (t) {
      var len = ipp[type].encodingLength({})
      t.deepEqual(len, 9)
      t.end()
    })

    test(type + ' groups', function (t) {
      var date = new Date(2015, 11, 1, 1, 23, 45, 678)
      var obj = { // version + statusCode + operationId/requestId: +8
        groups: [
          { tag: 0, attributes: [ // +1 (9)
            { tag: C.KEYWORD, name: 'string', value: 'foo' }, // +1+2+6+2+3=14 (23)
            { tag: C.KEYWORD, name: 'array', value: ['foo', 'bar'] }, // +1+2+5+2+3+1+2+0+2+3=21 (44)
            { tag: C.BOOLEAN, name: 'bool', value: true }, // +1+2+4+2+1=10 (54)
            { tag: C.ENUM, name: 'enum', value: 1 } // +1+2+4+2+4=13 (67)
          ] },
          { tag: 1, attributes: [ // +1 (68)
            { tag: C.KEYWORD, name: 'string', value: ['foo'] }, // +1+2+6+2+3=14 (82)
            { tag: C.TEXT_WITH_LANG, name: 'text-with-language', value: { lang: 'fr-CA', value: 'fou' } }, // +1+2+18+2+2+5+2+3=35 (117)
            { tag: C.DATE_TIME, name: 'date-time', value: date } // +1+2+9+2+11=25 (142)
          ] }
        ]
      } // end tag: +1 (143)
      var len = ipp[type].encodingLength(obj)
      t.deepEqual(len, 143)
      t.end()
    })

    test(type + ' data', function (t) {
      var obj = { data: new Buffer('foo') }
      var len = ipp[type].encodingLength(obj)
      t.deepEqual(len, 12)
      t.end()
    })

    test(type + ' data + groups', function (t) {
      var obj = { // version + statusCode + operationId/requestId: +8
        groups: [
          { tag: 1, attributes: [ // +1 (9)
            { tag: C.KEYWORD, name: 'string', value: 'foo' } // +1+2+6+2+3=14 (23)
          ] }
        ],
        data: new Buffer('foo') // +3 (26)
      } // end tag: +1 (27)
      var len = ipp[type].encodingLength(obj)
      t.deepEqual(len, 27)
      t.end()
    })
  })
})

test('encode', function (t) {
  t.test('request', function (t) {
    t.test('minimal', function (t) {
      var obj = {
        operationId: C.PRINT_JOB,
        requestId: 42
      }
      var encoded = ipp.request.encode(obj)
      var expected = new Buffer('010100020000002a03', 'hex')
      t.deepEqual(encoded, expected)
      t.end()
    })
  })

  t.test('response', function (t) {
    t.test('minimal', function (t) {
      var obj = {
        statusCode: C.SERVER_ERROR_VERSION_NOT_SUPPORTED,
        requestId: 42
      }
      var encoded = ipp.response.encode(obj)
      var expected = new Buffer('010105030000002a03', 'hex')
      t.deepEqual(encoded, expected)
      t.end()
    })

    t.test('custom version', function (t) {
      var obj = {
        version: { major: 2, minor: 0 },
        statusCode: C.SUCCESSFUL_OK,
        requestId: 42
      }
      var encoded = ipp.response.encode(obj)
      var expected = new Buffer('020000000000002a03', 'hex')
      t.deepEqual(encoded, expected)
      t.end()
    })

    test('groups', function (t) {
      var date = new Date(2015, 11, 1, 1, 23, 45, 678)
      var sign = date.getTimezoneOffset() > 0 ? '2d' : '2b'
      var zone = new Buffer(2)
      zone.writeInt8(date.getTimezoneOffset() / 60, 0)
      zone.writeInt8(date.getTimezoneOffset() % 60, 1)
      var dateHex = '07df0c0101172d06' + sign + zone.toString('hex')

      var obj = {
        statusCode: C.SUCCESSFUL_OK,
        requestId: 42,
        groups: [
          { tag: C.OPERATION_ATTRIBUTES_TAG, attributes: [
            { tag: C.KEYWORD, name: 'string', value: 'foo' },
            { tag: C.KEYWORD, name: 'array', value: ['foo', 'bar'] },
            { tag: C.BOOLEAN, name: 'bool', value: true },
            { tag: C.ENUM, name: 'enum', value: 42 }
          ] },
          { tag: C.JOB_ATTRIBUTES_TAG, attributes: [
            { tag: C.KEYWORD, name: 'string', value: ['foo'] },
            { tag: C.NAME_WITH_LANG, name: 'name-with-language', value: { lang: 'fr-CA', value: 'fou' } },
            { tag: C.DATE_TIME, name: 'date-time', value: date }
          ] }
        ]
      }
      var encoded = ipp.response.encode(obj)
      var expected = new Buffer(
        '0101' + // version
        '0000' + // statusCode
        '0000002a' + // requestId
        '01' + // delimiter tag
          '44' + // value tag
            '0006' + // name length
            '737472696e67' + // name
            '0003' + // value length
            '666f6f' + // value
          '44' + // value tag
            '0005' + // name length
            '6172726179' + // name
            '0003' + // value length
            '666f6f' + // value
          '44' + // value tag
            '0000' + // name length
            '' + // name
            '0003' + // value length
            '626172' + // value
          '22' + // value tag
            '0004' + // name length
            '626f6f6c' + // name
            '0001' + // value length
            '01' + // value
          '23' + // value tag
            '0004' + // name length
            '656e756d' + // name
            '0004' + // value length
            '0000002a' + // value
        '02' + // delimiter tag
          '44' + // value tag
            '0006' + // name length
            '737472696e67' + // name
            '0003' + // value length
            '666f6f' + // value
          '36' + // value tag
            '0012' + // name length
            '6e616d652d776974682d6c616e6775616765' + // name
            '000c' + // value length
            '0005' + // sub-value length
            '66722d4341' + // sub-value
            '0003' + // sub-value length
            '666f75' + // name
          '31' + // value tag
            '0009' + // name length
            '646174652d74696d65' + // name
            '000b' + // value length
            dateHex + // value
        '03', // end of attributes tag
        'hex')
      t.deepEqual(encoded, expected)
      t.end()
    })

    test('data', function (t) {
      var obj = {
        statusCode: C.SUCCESSFUL_OK, // +2 (4)
        requestId: 42, // +4 (8)
        data: new Buffer('foo')
      }
      var encoded = ipp.response.encode(obj)
      var expected = new Buffer(
        '0101' + // version
        '0000' + // statusCode
        '0000002a' + // requestId
        '03' + // end of attributes tag
        '666f6f', // data
        'hex')
      t.deepEqual(encoded, expected)
      t.end()
    })

    test('data + groups', function (t) {
      var obj = { // version: 2
        statusCode: C.SUCCESSFUL_OK, // +2 (4)
        requestId: 42, // +4 (8)
        groups: [
          { tag: C.JOB_ATTRIBUTES_TAG, attributes: [ // +1 (64)
            { tag: C.KEYWORD, name: 'string', value: 'foo' } // +1+2+6+2+3=14 (78)
          ] }
        ],
        data: new Buffer('foo')
      } // end tag: +1 (79)
      var encoded = ipp.response.encode(obj)
      var expected = new Buffer(
        '0101' + // version
        '0000' + // statusCode
        '0000002a' + // requestId
        '02' + // delimiter tag
          '44' + // value tag
            '0006' + // name length
            '737472696e67' + // name
            '0003' + // value length
            '666f6f' + // value
        '03' + // end of attributes tag
        '666f6f', // data
        'hex')
      t.deepEqual(encoded, expected)
      t.end()
    })
  })
})

test('decode', function (t) {
  t.test('request', function (t) {
    t.test('minimal', function (t) {
      var data = new Buffer('0101000a0000002a03', 'hex')
      var expected = {
        version: { major: 1, minor: 1 },
        operationId: 10,
        requestId: 42,
        groups: [],
        data: new Buffer(0)
      }
      var decoded = ipp.request.decode(data)
      t.deepEqual(decoded, expected)
      t.end()
    })

    t.test('truncated', function (t) {
      var data = new Buffer('0101000a0000002a', 'hex')
      t.throws(function () {
        ipp.request.decode(data)
      })
      t.end()
    })
  })
})

test('encode -> decode', function (t) {
  var encodeDate = new Date(2015, 11, 1, 1, 23, 45, 678)
  var decodeDate = new Date(2015, 11, 1, 1, 23, 45, 600)
  var obj = {
    version: { major: 1, minor: 0 },
    statusCode: C.SUCCESSFUL_OK,
    requestId: 42,
    groups: [
      { tag: C.OPERATION_ATTRIBUTES_TAG, attributes: [
        { tag: C.KEYWORD, name: 'string', value: ['foo'] },
        { tag: C.KEYWORD, name: 'array', value: ['foo', 'bar'] },
        { tag: C.BOOLEAN, name: 'bool', value: [true] },
        { tag: C.ENUM, name: 'enum', value: [42] }
      ] },
      { tag: C.JOB_ATTRIBUTES_TAG, attributes: [
        { tag: C.KEYWORD, name: 'string', value: ['foo'] },
        { tag: C.DATE_TIME, name: 'date-time', value: [encodeDate] }
      ] }
    ],
    data: new Buffer('foo')
  }
  var encoded = ipp.response.encode(obj)
  obj.groups[1].attributes[1].value[0] = decodeDate
  var decoded = ipp.response.decode(encoded)
  t.deepEqual(decoded, obj)
  t.end()
})
<|endoftext|>