mirror of
https://github.com/chenasraf/nextcloud-autocurrency.git
synced 2026-05-18 01:29:05 +00:00
feat: api controller poc
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -21,11 +21,26 @@ class ApiController extends OCSController {
|
||||
*
|
||||
* 200: Data returned
|
||||
*/
|
||||
// #[NoAdminRequired]
|
||||
// #[ApiRoute(verb: 'GET', url: '/api')]
|
||||
// public function index(): DataResponse {
|
||||
// return new DataResponse(
|
||||
// ['message' => 'Hello world!']
|
||||
// );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get current cron information
|
||||
*
|
||||
* @return DataResponse<Http::STATUS_OK, array{last_update:string,interval:int}, array{}>
|
||||
*
|
||||
* 200: Data returned
|
||||
*/
|
||||
#[NoAdminRequired]
|
||||
#[ApiRoute(verb: 'GET', url: '/api')]
|
||||
public function index(): DataResponse {
|
||||
#[ApiRoute(verb: 'GET', url: '/api/cron')]
|
||||
public function getCronInfo(): DataResponse {
|
||||
return new DataResponse(
|
||||
['message' => 'Hello world!']
|
||||
['last_update' => '2021-09-01 00:00:00', 'interval' => 24]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"npm": "^10.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"dev": "vite build --watch",
|
||||
"build": "vue-tsc -b && vite build",
|
||||
"preview": "vite preview",
|
||||
"lint": "eslint src",
|
||||
|
||||
21
src/App.vue
21
src/App.vue
@@ -9,6 +9,7 @@
|
||||
:options="intervals"
|
||||
input-label="Currency conversion rate update interval"
|
||||
required
|
||||
:disabled="interval == null"
|
||||
/>
|
||||
<div class="submit-buttons">
|
||||
<NcButton native-type="submit">Save</NcButton>
|
||||
@@ -24,6 +25,7 @@
|
||||
import NcAppSettingsSection from '@nextcloud/vue/dist/Components/NcAppSettingsSection.js'
|
||||
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'
|
||||
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
|
||||
import axios from '@nextcloud/axios'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
@@ -47,9 +49,26 @@ export default {
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.interval = this.getIntervalByValue(24).label
|
||||
// this.interval = this.getIntervalByValue(24).label
|
||||
this.fetchSettings()
|
||||
},
|
||||
methods: {
|
||||
async fetchSettings() {
|
||||
try {
|
||||
const resp = await axios.get('/cron')
|
||||
const data = resp.data.ocs.data
|
||||
console.debug('[DEBUG] Settings fetched', data)
|
||||
const interval = this.getIntervalByValue(data.interval)
|
||||
if (interval) {
|
||||
console.debug('[DEBUG] Interval found', interval)
|
||||
this.interval = interval.label
|
||||
} else {
|
||||
console.warn('Invalid interval value', data.interval)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to fetch settings', e)
|
||||
}
|
||||
},
|
||||
getIntervalByValue(value) {
|
||||
return this.intervalOptions.find((x) => x.value === value)
|
||||
},
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import App from './App.vue'
|
||||
import './style.scss'
|
||||
import { createApp } from 'vue'
|
||||
import axios from '@nextcloud/axios'
|
||||
import { generateUrl, generateOcsUrl } from '@nextcloud/router'
|
||||
|
||||
console.log('Mounting AutoCurrency Settings')
|
||||
const baseURL = generateOcsUrl('/apps/autocurrency/api')
|
||||
axios.defaults.baseURL = baseURL
|
||||
|
||||
console.log('[DEBUG] Mounting AutoCurrency Settings')
|
||||
console.log('[DEBUG] Base URL:', baseURL)
|
||||
createApp(App).mount('#autocurrency-settings')
|
||||
|
||||
Reference in New Issue
Block a user