|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +<template> |
| 19 | + <div> |
| 20 | + <resource-layout> |
| 21 | + <template #left> |
| 22 | + <a-card :bordered="false"> |
| 23 | + <a-auto-complete |
| 24 | + v-model:value="query" |
| 25 | + :options="options.filter(value => value.value.toLowerCase().includes(query.toLowerCase()))" |
| 26 | + style="width: 100%" |
| 27 | + > |
| 28 | + <a-input-search |
| 29 | + size="default" |
| 30 | + :placeholder="$t('label.search')" |
| 31 | + v-model:value="query" |
| 32 | + allow-clear |
| 33 | + enter-button |
| 34 | + > |
| 35 | + <template #prefix><search-outlined /></template> |
| 36 | + </a-input-search> |
| 37 | + </a-auto-complete> |
| 38 | + <a-list style="margin-top: 12px; height:580px; overflow-y: scroll;" size="small" :data-source="Object.keys($store.getters.apis).sort()"> |
| 39 | + <template #renderItem="{ item }"> |
| 40 | + <a> |
| 41 | + <a-list-item |
| 42 | + v-if="item.toLowerCase().includes(query.toLowerCase())" |
| 43 | + @click="showApi(item)" |
| 44 | + style="padding-left: 12px" |
| 45 | + :class="selectedApi === item ? 'selected-item' : ''"> |
| 46 | + {{ item }} <a-tag v-if="$store.getters.apis[item].isasync" color="blue">async</a-tag> |
| 47 | + </a-list-item> |
| 48 | + </a> |
| 49 | + </template> |
| 50 | + </a-list> |
| 51 | + <a-divider style="margin-bottom: 12px" /> |
| 52 | + <span>{{ Object.keys($store.getters.apis).length }} {{ $t('label.api.docs.count') }}</span> |
| 53 | + </a-card> |
| 54 | + </template> |
| 55 | + <template #right> |
| 56 | + <a-card |
| 57 | + class="spin-content" |
| 58 | + :bordered="true" |
| 59 | + style="width: 100%; overflow-x: auto"> |
| 60 | + <span v-if="selectedApi && selectedApi in $store.getters.apis"> |
| 61 | + <h2>{{ selectedApi }} |
| 62 | + <a-tag v-if="$store.getters.apis[selectedApi].isasync" color="blue">Asynchronous API</a-tag> |
| 63 | + <a-tag v-if="$store.getters.apis[selectedApi].since">Since {{ $store.getters.apis[selectedApi].since }}</a-tag> |
| 64 | + <tooltip-button |
| 65 | + tooltipPlacement="right" |
| 66 | + :tooltip="$t('label.copy') + ' ' + selectedApi" |
| 67 | + icon="CopyOutlined" |
| 68 | + type="outlined" |
| 69 | + size="small" |
| 70 | + @onClick="$message.success($t('label.copied.clipboard'))" |
| 71 | + :copyResource="selectedApi" /> |
| 72 | + </h2> |
| 73 | + <p>{{ $store.getters.apis[selectedApi].description }}</p> |
| 74 | + <h3>{{ $t('label.request') }} {{ $t('label.params') }}:</h3> |
| 75 | + <a-table |
| 76 | + :columns="[{title: $t('label.name'), dataIndex: 'name'}, {title: $t('label.required'), dataIndex: 'required'}, {title: $t('label.type'), dataIndex: 'type'}, {title: $t('label.description'), dataIndex: 'description'}]" |
| 77 | + :data-source="selectedParams" |
| 78 | + :pagination="false" |
| 79 | + size="small"> |
| 80 | + <template #bodyCell="{text, column, record}"> |
| 81 | + <a-tag v-if="record.since && column.dataIndex === 'description'">Since {{ record.since }}</a-tag> |
| 82 | + <span v-if="record.required === true"><strong>{{ text }}</strong></span> |
| 83 | + <span v-else>{{ text }}</span> |
| 84 | + </template> |
| 85 | + </a-table> |
| 86 | + <br/> |
| 87 | + <h3>{{ $t('label.response') }} {{ $t('label.params') }}:</h3> |
| 88 | + <a-table |
| 89 | + :columns="[{title: $t('label.name'), dataIndex: 'name'}, {title: $t('label.type'), dataIndex: 'type'}, {title: $t('label.description'), dataIndex: 'description'}]" |
| 90 | + :data-source="selectedResponse" |
| 91 | + :pagination="false" |
| 92 | + size="small" /> |
| 93 | + </span> |
| 94 | + <span v-else> |
| 95 | + <a-alert |
| 96 | + :message="$t('label.api.docs')" |
| 97 | + type="info" |
| 98 | + show-icon |
| 99 | + banner> |
| 100 | + <template #description> |
| 101 | + <a href="https://docs.cloudstack.apache.org/en/latest/developersguide/dev.html" target="_blank">{{ $t('label.api.docs.description') }}</a> |
| 102 | + </template> |
| 103 | + </a-alert> |
| 104 | + <a-result |
| 105 | + status="success" |
| 106 | + :title="$t('label.download') + ' CloudStack CloudMonkey CLI'" |
| 107 | + sub-title="For API automation and orchestration" |
| 108 | + > |
| 109 | + <template #extra> |
| 110 | + <a-button type="primary"><a href="https://github.com/apache/cloudstack-cloudmonkey/releases" target="_blank">{{ $t('label.download') }} CLI</a></a-button> |
| 111 | + <a-button><a href="https://github.com/apache/cloudstack-cloudmonkey/wiki/Usage" target="_blank">{{ $t('label.open.documentation') }} (CLI)</a></a-button> |
| 112 | + <br/> |
| 113 | + <br/> |
| 114 | + <div v-if="showKeys"> |
| 115 | + <key-outlined /> |
| 116 | + <strong> |
| 117 | + {{ $t('label.apikey') }} |
| 118 | + <tooltip-button |
| 119 | + tooltipPlacement="right" |
| 120 | + :tooltip="$t('label.copy') + ' ' + $t('label.apikey')" |
| 121 | + icon="CopyOutlined" |
| 122 | + type="dashed" |
| 123 | + size="small" |
| 124 | + @onClick="$message.success($t('label.copied.clipboard'))" |
| 125 | + :copyResource="userkeys.apikey" /> |
| 126 | + </strong> |
| 127 | + <div> |
| 128 | + {{ userkeys.apikey.substring(0, 20) }}... |
| 129 | + </div> |
| 130 | + <br/> |
| 131 | + <lock-outlined /> |
| 132 | + <strong> |
| 133 | + {{ $t('label.secretkey') }} |
| 134 | + <tooltip-button |
| 135 | + tooltipPlacement="right" |
| 136 | + :tooltip="$t('label.copy') + ' ' + $t('label.secretkey')" |
| 137 | + icon="CopyOutlined" |
| 138 | + type="dashed" |
| 139 | + size="small" |
| 140 | + @onClick="$message.success($t('label.copied.clipboard'))" |
| 141 | + :copyResource="userkeys.secretkey" /> |
| 142 | + </strong> |
| 143 | + <div> |
| 144 | + {{ userkeys.secretkey.substring(0, 20) }}... |
| 145 | + </div> |
| 146 | + </div> |
| 147 | + </template> |
| 148 | + </a-result> |
| 149 | + </span> |
| 150 | + </a-card> |
| 151 | + </template> |
| 152 | + </resource-layout> |
| 153 | + </div> |
| 154 | +</template> |
| 155 | + |
| 156 | +<script> |
| 157 | +import { api } from '@/api' |
| 158 | +
|
| 159 | +import ResourceLayout from '@/layouts/ResourceLayout' |
| 160 | +import TooltipButton from '@/components/widgets/TooltipButton' |
| 161 | +
|
| 162 | +export default { |
| 163 | + name: 'ApiDocsPlugin', |
| 164 | + components: { |
| 165 | + ResourceLayout, |
| 166 | + TooltipButton |
| 167 | + }, |
| 168 | + data () { |
| 169 | + return { |
| 170 | + query: '', |
| 171 | + selectedApi: '', |
| 172 | + selectedParams: [], |
| 173 | + selectedResponse: [], |
| 174 | + showKeys: false, |
| 175 | + userkeys: {}, |
| 176 | + options: [ |
| 177 | + { value: 'VirtualMachine', label: 'Instance' }, |
| 178 | + { value: 'Kubernetes', label: 'Kubernetes' }, |
| 179 | + { value: 'Volume', label: 'Volume' }, |
| 180 | + { value: 'Snapshot', label: 'Snapshot' }, |
| 181 | + { value: 'Backup', label: 'Backup' }, |
| 182 | + { value: 'Network', label: 'Network' }, |
| 183 | + { value: 'IpAddress', label: 'IP Address' }, |
| 184 | + { value: 'VPN', label: 'VPN' }, |
| 185 | + { value: 'VPC', label: 'VPC' }, |
| 186 | + { value: 'NetworkACL', label: 'Network ACL' }, |
| 187 | + { value: 'SecurityGroup', label: 'Security Group' }, |
| 188 | + { value: 'Template', label: 'Template' }, |
| 189 | + { value: 'ISO', label: 'ISO' }, |
| 190 | + { value: 'SSH', label: 'SSH' }, |
| 191 | + { value: 'Project', label: 'Project' }, |
| 192 | + { value: 'Account', label: 'Account' }, |
| 193 | + { value: 'User', label: 'User' }, |
| 194 | + { value: 'Event', label: 'Event' }, |
| 195 | + { value: 'Offering', label: 'Offering' }, |
| 196 | + { value: 'Zone', label: 'Zone' } |
| 197 | + ] |
| 198 | + } |
| 199 | + }, |
| 200 | + created () { |
| 201 | + if (!('getUserKeys' in this.$store.getters.apis)) { |
| 202 | + return |
| 203 | + } |
| 204 | + api('getUserKeys', { id: this.$store.getters.userInfo.id }).then(json => { |
| 205 | + this.userkeys = json.getuserkeysresponse.userkeys |
| 206 | + if (this.userkeys && this.userkeys.secretkey) { |
| 207 | + this.showKeys = true |
| 208 | + } |
| 209 | + }) |
| 210 | + }, |
| 211 | + methods: { |
| 212 | + showApi (api) { |
| 213 | + this.selectedApi = api |
| 214 | + this.selectedParams = this.$store.getters.apis[api].params |
| 215 | + .sort((a, b) => (a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0)) |
| 216 | + .sort((a, b) => (a.required > b.required) ? -1 : ((b.required > a.required) ? 1 : 0)) |
| 217 | + .filter(value => Object.keys(value).length > 0) |
| 218 | + this.selectedResponse = this.$store.getters.apis[api].response.filter(value => Object.keys(value).length > 0) |
| 219 | + } |
| 220 | + } |
| 221 | +} |
| 222 | +</script> |
0 commit comments