Skip to content
Snippets Groups Projects
Commit d1a84b68 authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

New: Add Resource interaction functionality

parent ba9369b1
Branches
Tags
No related merge requests found
......@@ -11,6 +11,7 @@ export { DataSourceApi } from './requests/datasource-api'
export { VisibilityApi } from './requests/visibility-api'
export { InstituteApi } from './requests/institute-api'
export { DisciplineApi } from './requests/discipline-api'
export { LicenseApi } from './requests/license-api'
const headerKey = 'Authorization'
......
......
const axios = require('axios');
import fileSaver from 'file-saver';
const axios = require('axios')
import fileSaver from 'file-saver'
import apiConnection from '../api-connection';
import apiConnection from '../api-connection'
function getDataSourceApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/DataSource/';
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/DataSource/'
}
export class DataSourceApi {
public static getDataSourceFolder(resourceId: any, path: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
public static getDataSourceFolder(
resourceId: any,
path: string,
thenHandler: any,
catchHandler: any
) {
apiConnection.setHeader()
axios
.get(getDataSourceApiUrl() + resourceId + path)
.get(getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path))
.then(thenHandler)
.catch(catchHandler);
.catch(catchHandler)
}
public static downloadDataSourceFile(resourceId: any, path: string, name: string, catchHandler: any) {
apiConnection.setHeader();
axios.get(getDataSourceApiUrl() + resourceId + path, {responseType: 'blob'}).then((response: any) => {
public static downloadDataSourceFile(
resourceId: any,
path: string,
name: string,
catchHandler: any
) {
apiConnection.setHeader()
axios
.get(getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path), {
responseType: 'blob'
})
.then((response: any) => {
// Let the user save the file.
// The data is cached until the response is completed!
fileSaver.saveAs(response.data, name);
}).catch(catchHandler);
fileSaver.saveAs(response.data, name)
})
.catch(catchHandler)
}
public static getDataSource(resourceId: any, path: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
axios
.get(getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path))
.then(thenHandler)
.catch(catchHandler)
}
public static delete(resourceId: any, path: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
axios
.delete(getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path))
.then(thenHandler)
.catch(catchHandler)
}
public static Upload(resourceId: any, path: any, data: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
axios({
method: 'PUT',
url: getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path),
headers: {
'Content-Type': 'application/binary'
},
data
})
.then(thenHandler)
.catch(catchHandler)
}
public static Update(resourceId: any, path: any, data: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
axios({
method: 'PUT',
url: getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path) + '/update',
headers: {
'Content-Type': 'application/binary'
},
data
})
.then(thenHandler)
.catch(catchHandler)
}
}
const axios = require('axios')
import apiConnection from '../api-connection'
function getLicenseApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/License/'
}
export class LicenseApi {
public static getLicenses(thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
axios
.get(getLicenseApiUrl())
.then(thenHandler)
.catch(catchHandler)
}
}
const axios = require('axios');
const axios = require('axios')
import apiConnection from '../api-connection';
import apiConnection from '../api-connection'
function getResourceApiUrl() {
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/Resource/';
return 'https://' + apiConnection.getHostName() + '/coscine/api/Coscine.Api.Project/Resource/'
}
export class ResourceApi {
public static getResourceInformation(resourceId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
axios
.get(getResourceApiUrl() + resourceId)
.then(thenHandler)
.catch(catchHandler)
}
public static storeResource(parentId: string, body: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
apiConnection.setHeader()
axios
.post(getResourceApiUrl() + 'Project/' + parentId, body)
.then(thenHandler)
.catch(catchHandler);
.catch(catchHandler)
}
public static deleteResource(resourceId: string, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
axios
.delete(getResourceApiUrl() + resourceId)
.then(thenHandler)
.catch(catchHandler)
}
public static updateResource(resourceId: string, body: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader()
axios
.post(getResourceApiUrl() + resourceId, body)
.then(thenHandler)
.catch(catchHandler)
}
}
......@@ -14,4 +14,11 @@ export class ResourceTypeApi {
.then(thenHandler)
.catch(catchHandler);
}
public static getFields(resourceTypeId: any, thenHandler: any, catchHandler: any) {
apiConnection.setHeader();
axios
.get(getResourceTypeApiUrl() + resourceTypeId + '/fields')
.then(thenHandler)
.catch(catchHandler);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment