|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <div class="form-label-group"> |
| 4 | + <input v-model="search" v-on:keydown="loadPage(0); checkUser();" class="form-control search" required="" autofocus="" autocomplete="off" type="text" onsubmit="return false"> |
| 5 | + |
| 6 | + <label for="inputEmail">Type in a GitHub username or organization...</label> |
| 7 | + </div> |
| 8 | + |
| 9 | + <ul class="list-group"> |
| 10 | + <li v-if="search && exists !== true" class="list-group-item d-flex justify-content-between align-items-center"> |
| 11 | + <span><i class="fas fa-user"></i> {{search}}</span> |
| 12 | + <button type="button" class="btn btn-sm btn-success" v-bind:disabled="!isValidUser" v-on:click="addUser"> |
| 13 | + <i class="fas fa-plus"></i> Add |
| 14 | + </button> |
| 15 | + </li> |
| 16 | + |
| 17 | + <li v-for="user in users" class="list-group-item "> |
| 18 | + <div class="d-flex justify-content-between align-items-center"> |
| 19 | + <span><i class="fas fa-user"></i> {{user.username | truncateUsername}}</span> |
| 20 | + |
| 21 | + <div class="btn-group" role="group" aria-label="Basic example"> |
| 22 | + |
| 23 | + <router-link v-bind:to="'/user/' + user.username"> |
| 24 | + <button type="button" class="btn btn-sm btn-outline-dark"> |
| 25 | + <i class="fas fa-code-branch"></i> View {{user.totalRepos}}/{{user.reportedRepos}} Repos |
| 26 | + </button> |
| 27 | + </router-link> |
| 28 | + |
| 29 | + |
| 30 | + <button type="button" class="btn btn-sm" v-bind:class="{ |
| 31 | + 'btn-outline-success': user.status === 'synced', |
| 32 | + 'btn-outline-warning': user.status === 'syncing', |
| 33 | + 'btn-outline-danger': user.status === 'unsynced', |
| 34 | + 'btn-outline-dark': user.status === 'error' |
| 35 | + }"> |
| 36 | + <i class="fas fa-sync-alt"></i> {{user.status | capitalize}} |
| 37 | + </button> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + </li> |
| 41 | + </ul> |
| 42 | + |
| 43 | + <nav aria-label="Page navigation example"> |
| 44 | + <ul class="pagination justify-content-center"> |
| 45 | + <li class="page-item" v-bind:class="{ disabled: page === 0}"> |
| 46 | + <a v-on:click="loadPage(page - 1)" class="page-link" href="#" tabindex="-1">Previous</a> |
| 47 | + </li> |
| 48 | + |
| 49 | + <li v-if="page === 0" class="page-item disabled"><a class="page-link" href="#">0</a></li> |
| 50 | + <li v-if="page === 0 && totalPages > 1" class="page-item"><a class="page-link" v-on:click="loadPage(1)" href="#">1</a></li> |
| 51 | + <li v-if="page === 0 && totalPages > 2" class="page-item"><a class="page-link" v-on:click="loadPage(2)" href="#">2</a></li> |
| 52 | + |
| 53 | + <li v-if="page !== 0 && page !== totalPages - 1" class="page-item"><a class="page-link" v-on:click="loadPage(page - 1)" href="#">{{page - 1}}</a></li> |
| 54 | + <li v-if="page !== 0 && page !== totalPages - 1 && totalPages > 1" class="page-item disabled"><a class="page-link" v-on:click="loadPage(page)" href="#">{{page}}</a></li> |
| 55 | + <li v-if="page !== 0 && page !== totalPages - 1 && totalPages > 2" class="page-item"><a class="page-link" v-on:click="loadPage(page + 1)" href="#">{{page + 1}}</a></li> |
| 56 | + |
| 57 | + <li v-if="page !== 0 && page === totalPages - 1" class="page-item"><a class="page-link" v-on:click="loadPage(page - 2)" href="#">{{page - 2}}</a></li> |
| 58 | + <li v-if="page !== 0 && page === totalPages - 1 && totalPages > 1" class="page-item"><a class="page-link" v-on:click="loadPage(page - 1)" href="#">{{page - 1}}</a></li> |
| 59 | + <li v-if="page !== 0 && page === totalPages - 1 && totalPages > 2" class="page-item disabled"><a class="page-link" v-on:click="loadPage(page)" href="#">{{page}}</a></li> |
| 60 | + |
| 61 | + <li class="page-item" v-bind:class="{ disabled: page + 1 == totalPages}"> |
| 62 | + <a v-on:click="loadPage(page + 1)" class="page-link" href="#">Next</a> |
| 63 | + </li> |
| 64 | + </ul> |
| 65 | + </nav> |
| 66 | + </div> |
| 67 | +</template> |
| 68 | + |
| 69 | +<script> |
| 70 | +const axios = require('axios'); |
| 71 | +
|
| 72 | +const capitalize = require('../lib/capitalize'); |
| 73 | +
|
| 74 | +const CancelToken = axios.CancelToken; |
| 75 | +const urlParams = new URLSearchParams(location.search); |
| 76 | +
|
| 77 | +let repoListTimeout; |
| 78 | +
|
| 79 | +module.exports = { |
| 80 | + data: () => ({ |
| 81 | + search: '', |
| 82 | + isValidUser: false, |
| 83 | + users: [], |
| 84 | + page: 0, |
| 85 | + totalPages: 0, |
| 86 | + exists: false, |
| 87 | + cloneRepo: false, |
| 88 | + cancelPreviousCheckUser: null |
| 89 | + }), |
| 90 | + methods: { |
| 91 | + async checkUser() { |
| 92 | + if(this.search.trim().length < 1) { |
| 93 | + return; |
| 94 | + } |
| 95 | +
|
| 96 | + if(this.cancelPreviousCheckUser !== null) { |
| 97 | + this.cancelPreviousCheckUser(); |
| 98 | + } |
| 99 | +
|
| 100 | + const {data} = await axios.get(`/isvaliduser/${this.search}`, { |
| 101 | + cancelToken: new CancelToken(c => this.cancelPreviousCheckUser = c) |
| 102 | + }); |
| 103 | +
|
| 104 | + this.isValidUser = data; |
| 105 | + }, |
| 106 | + async addUser() { |
| 107 | + await axios.get(`/adduser/${this.search}`); |
| 108 | + await this.loadPage(this.page); |
| 109 | + }, |
| 110 | + async loadPage(i) { |
| 111 | + i = typeof i !== 'undefined' ? i : this.page; |
| 112 | +
|
| 113 | + const {data: {users, exists, total, totalPages}} = await axios.get(`/userlist/${i.toString()}`, { |
| 114 | + params: { |
| 115 | + filter: this.search |
| 116 | + } |
| 117 | + }); |
| 118 | +
|
| 119 | + this.users = users; |
| 120 | + this.exists = exists; |
| 121 | + this.page = i; |
| 122 | + this.totalPages = totalPages; |
| 123 | + this.totalUsers = total; |
| 124 | + } |
| 125 | + }, |
| 126 | + filters: { |
| 127 | + capitalize, |
| 128 | + truncateUsername: function (value) { |
| 129 | + const length = 30; |
| 130 | +
|
| 131 | + if(!value) return ''; |
| 132 | +
|
| 133 | + if(value.length < length) { |
| 134 | + return value; |
| 135 | + } |
| 136 | +
|
| 137 | + return `${value.slice(0, length)}...`; |
| 138 | + } |
| 139 | + }, |
| 140 | + async created() { |
| 141 | + this.loadPage(0); |
| 142 | +
|
| 143 | + setInterval(() => { |
| 144 | + this.loadPage(); |
| 145 | + }, 10 * 1000); |
| 146 | + } |
| 147 | +}; |
| 148 | +</script> |
0 commit comments