YouTube.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <div class="admin-tab container">
  3. <page-metadata title="Admin | YouTube" />
  4. <div class="card tab-info">
  5. <div class="info-row">
  6. <h1>YouTube API</h1>
  7. <p>
  8. Analyze YouTube quota usage and API requests made on this
  9. instance
  10. </p>
  11. </div>
  12. <div class="button-row">
  13. <run-job-dropdown :jobs="jobs" />
  14. </div>
  15. </div>
  16. <div class="card charts">
  17. <div class="chart">
  18. <h4 class="has-text-centered">Quota Usage</h4>
  19. <line-chart
  20. chart-id="youtube-quota-usage"
  21. :data="charts.quotaUsage"
  22. />
  23. </div>
  24. <div class="chart">
  25. <h4 class="has-text-centered">API Requests</h4>
  26. <line-chart
  27. chart-id="youtube-api-requests"
  28. :data="charts.apiRequests"
  29. />
  30. </div>
  31. </div>
  32. <div class="card">
  33. <h4>Quota Stats</h4>
  34. <hr class="section-horizontal-rule" />
  35. <div class="card-content">
  36. <p v-if="fromDate">As of {{ fromDate }}</p>
  37. <div
  38. v-for="[quotaName, quotaObject] in Object.entries(
  39. quotaStatus
  40. )"
  41. :key="quotaName"
  42. >
  43. <p>{{ quotaName }}</p>
  44. <hr />
  45. <p>Quota used: {{ quotaObject.quotaUsed }}</p>
  46. <p>Limit: {{ quotaObject.limit }}</p>
  47. <p>Quota exceeded: {{ quotaObject.quotaExceeded }}</p>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="card">
  52. <h4>API Requests</h4>
  53. <hr class="section-horizontal-rule" />
  54. <advanced-table
  55. :column-default="columnDefault"
  56. :columns="columns"
  57. :filters="filters"
  58. data-action="youtube.getApiRequests"
  59. name="admin-youtube-api-requests"
  60. :max-width="1140"
  61. >
  62. <template #column-options="slotProps">
  63. <div class="row-options">
  64. <button
  65. class="button is-primary icon-with-button material-icons"
  66. @click="
  67. openModal({
  68. modal: 'viewApiRequest',
  69. data: {
  70. requestId: slotProps.item._id
  71. }
  72. })
  73. "
  74. :disabled="slotProps.item.removed"
  75. content="View API Request"
  76. v-tippy
  77. >
  78. open_in_full
  79. </button>
  80. </div>
  81. </template>
  82. <template #column-_id="slotProps">
  83. <span :title="slotProps.item._id">{{
  84. slotProps.item._id
  85. }}</span>
  86. </template>
  87. <template #column-quotaCost="slotProps">
  88. <span :title="slotProps.item.quotaCost">{{
  89. slotProps.item.quotaCost
  90. }}</span>
  91. </template>
  92. <template #column-timestamp="slotProps">
  93. <span :title="new Date(slotProps.item.date)">{{
  94. getDateFormatted(slotProps.item.date)
  95. }}</span>
  96. </template>
  97. <template #column-url="slotProps">
  98. <span :title="slotProps.item.url">{{
  99. slotProps.item.url
  100. }}</span>
  101. </template>
  102. </advanced-table>
  103. </div>
  104. </div>
  105. </template>
  106. <script>
  107. import { mapActions, mapGetters } from "vuex";
  108. import AdvancedTable from "@/components/AdvancedTable.vue";
  109. import RunJobDropdown from "@/components/RunJobDropdown.vue";
  110. import LineChart from "@/components/LineChart.vue";
  111. import ws from "@/ws";
  112. export default {
  113. components: {
  114. AdvancedTable,
  115. RunJobDropdown,
  116. LineChart
  117. },
  118. data() {
  119. return {
  120. quotaStatus: {},
  121. fromDate: null,
  122. columnDefault: {
  123. sortable: true,
  124. hidable: true,
  125. defaultVisibility: "shown",
  126. draggable: true,
  127. resizable: true,
  128. minWidth: 150,
  129. maxWidth: 600
  130. },
  131. columns: [
  132. {
  133. name: "options",
  134. displayName: "Options",
  135. properties: ["_id"],
  136. hidable: false,
  137. resizable: false,
  138. minWidth: 76,
  139. defaultWidth: 76
  140. },
  141. {
  142. name: "quotaCost",
  143. displayName: "Quota Cost",
  144. properties: ["quotaCost"],
  145. sortProperty: ["quotaCost"],
  146. minWidth: 150,
  147. defaultWidth: 150
  148. },
  149. {
  150. name: "timestamp",
  151. displayName: "Timestamp",
  152. properties: ["date"],
  153. sortProperty: ["date"],
  154. minWidth: 150,
  155. defaultWidth: 150
  156. },
  157. {
  158. name: "url",
  159. displayName: "URL",
  160. properties: ["url"],
  161. sortProperty: ["url"]
  162. },
  163. {
  164. name: "_id",
  165. displayName: "Request ID",
  166. properties: ["_id"],
  167. sortProperty: ["_id"],
  168. minWidth: 230,
  169. defaultWidth: 230
  170. }
  171. ],
  172. filters: [
  173. {
  174. name: "_id",
  175. displayName: "Request ID",
  176. property: "_id",
  177. filterTypes: ["exact"],
  178. defaultFilterType: "exact"
  179. },
  180. {
  181. name: "quotaCost",
  182. displayName: "Quota Cost",
  183. property: "quotaCost",
  184. filterTypes: [
  185. "numberLesserEqual",
  186. "numberLesser",
  187. "numberGreater",
  188. "numberGreaterEqual",
  189. "numberEquals"
  190. ],
  191. defaultFilterType: "numberLesser"
  192. },
  193. {
  194. name: "timestamp",
  195. displayName: "Timestamp",
  196. property: "date",
  197. filterTypes: ["datetimeBefore", "datetimeAfter"],
  198. defaultFilterType: "datetimeBefore"
  199. },
  200. {
  201. name: "url",
  202. displayName: "URL",
  203. property: "url",
  204. filterTypes: ["contains", "exact", "regex"],
  205. defaultFilterType: "contains"
  206. }
  207. ],
  208. charts: {
  209. quotaUsage: {
  210. labels: [
  211. "Mon",
  212. "Tues",
  213. "Wed",
  214. "Thurs",
  215. "Fri",
  216. "Sat",
  217. "Sun"
  218. ],
  219. datasets: [
  220. {
  221. label: "Type A",
  222. data: [300, 122, 0, 67, 23, 280, 185],
  223. fill: true,
  224. borderColor: "rgb(2, 166, 242)"
  225. }
  226. ]
  227. },
  228. apiRequests: {
  229. labels: [
  230. "Mon",
  231. "Tues",
  232. "Wed",
  233. "Thurs",
  234. "Fri",
  235. "Sat",
  236. "Sun"
  237. ],
  238. datasets: [
  239. {
  240. label: "Type A",
  241. data: [30, 6, 0, 9, 4, 26, 19],
  242. borderColor: "rgb(2, 166, 242)"
  243. }
  244. ]
  245. }
  246. },
  247. jobs: [
  248. {
  249. name: "Reset stored API requests",
  250. socket: "youtube.resetStoredApiRequests"
  251. }
  252. ]
  253. };
  254. },
  255. computed: mapGetters({
  256. socket: "websockets/getSocket"
  257. }),
  258. mounted() {
  259. ws.onConnect(this.init);
  260. },
  261. methods: {
  262. init() {
  263. if (this.$route.query.fromDate)
  264. this.fromDate = this.$route.query.fromDate;
  265. this.socket.dispatch(
  266. "youtube.getQuotaStatus",
  267. this.fromDate,
  268. res => {
  269. if (res.status === "success")
  270. this.quotaStatus = res.data.status;
  271. }
  272. );
  273. },
  274. getDateFormatted(createdAt) {
  275. const date = new Date(createdAt);
  276. const year = date.getFullYear();
  277. const month = `${date.getMonth() + 1}`.padStart(2, 0);
  278. const day = `${date.getDate()}`.padStart(2, 0);
  279. const hour = `${date.getHours()}`.padStart(2, 0);
  280. const minute = `${date.getMinutes()}`.padStart(2, 0);
  281. return `${year}-${month}-${day} ${hour}:${minute}`;
  282. },
  283. ...mapActions("modalVisibility", ["openModal"])
  284. }
  285. };
  286. </script>
  287. <style lang="less" scoped>
  288. .night-mode {
  289. .table {
  290. color: var(--light-grey-2);
  291. background-color: var(--dark-grey-3);
  292. thead tr {
  293. background: var(--dark-grey-3);
  294. td {
  295. color: var(--white);
  296. }
  297. }
  298. tbody tr:hover {
  299. background-color: var(--dark-grey-4) !important;
  300. }
  301. tbody tr:nth-child(even) {
  302. background-color: var(--dark-grey-2);
  303. }
  304. strong {
  305. color: var(--light-grey-2);
  306. }
  307. }
  308. }
  309. td {
  310. vertical-align: middle;
  311. }
  312. .is-primary:focus {
  313. background-color: var(--primary-color) !important;
  314. }
  315. .card.charts {
  316. flex-direction: row !important;
  317. .chart {
  318. width: 50%;
  319. }
  320. @media screen and (max-width: 1100px) {
  321. flex-direction: column !important;
  322. .chart {
  323. width: unset;
  324. &:not(:first-child) {
  325. margin-top: 10px;
  326. }
  327. }
  328. }
  329. }
  330. </style>