Skip to main content
Sign in
Snippets Groups Projects
Commit 75100e47 authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

Refactoring

parent 61a73ed6
No related branches found
No related tags found
2 merge requests!25Add: Removing empty nodes from metadata json,!23Update: Removing empty nodes from metadata json
......@@ -75,7 +75,7 @@
]
},
"prettier": {
"semi": false,
"semi": true,
"singleQuote": true
},
"commitlint": {
......
......
const axios = require('axios')
const axios = require('axios');
const headerKey = 'Authorization'
const headerKey = 'Authorization';
let hostName = window.location.hostname
let hostName = window.location.hostname;
if (hostName.indexOf(':') !== -1) {
if (hostName.indexOf('https://') !== -1) {
hostName = hostName.replace('https://', '')
hostName = hostName.replace('https://', '');
}
hostName = hostName.substr(0, hostName.indexOf(':'))
hostName = hostName.substr(0, hostName.indexOf(':'));
}
export default {
getHostName() {
return hostName
return hostName;
},
setHeader() {
axios.defaults.headers.common[headerKey] = 'Bearer ' + (coscine as any).authorization.bearer
}
axios.defaults.headers.common[headerKey] = 'Bearer ' + (coscine as any).authorization.bearer;
}
};
const axios = require('axios')
import fileSaver from 'file-saver'
const axios = require('axios');
import fileSaver from 'file-saver';
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getDataSourceApiUrl() {
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/DataSource/'
)
);
}
export class DataSourceApi {
......@@ -16,11 +16,11 @@ export class DataSourceApi {
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path))
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static downloadDataSourceFile(
resourceId: any,
......@@ -28,7 +28,7 @@ export class DataSourceApi {
name: string,
catchHandler: any
) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path), {
responseType: 'blob'
......@@ -36,24 +36,24 @@ export class DataSourceApi {
.then((response: any) => {
// Let the user save the file.
// The data is cached until the response is completed!
fileSaver.saveAs(response.data, name)
fileSaver.saveAs(response.data, name);
})
.catch(catchHandler)
.catch(catchHandler);
}
public static getDataSource(resourceId: any, path: any, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path))
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static delete(resourceId: any, path: any, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.delete(getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path))
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static Upload(
......@@ -64,7 +64,7 @@ export class DataSourceApi {
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios({
method: 'PUT',
url: getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path),
......@@ -74,7 +74,7 @@ export class DataSourceApi {
data
})
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static Update(
......@@ -85,7 +85,7 @@ export class DataSourceApi {
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios({
method: 'PUT',
url: getDataSourceApiUrl() + resourceId + '/' + encodeURIComponent(path) + '/update',
......@@ -95,14 +95,14 @@ export class DataSourceApi {
data
})
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static isValidDataSource(body: any, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.post(getDataSourceApiUrl() + 'validate', body)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
const axios = require('axios')
const axios = require('axios');
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getDisciplineApiUrl() {
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Discipline/'
)
);
}
export class DisciplineApi {
public static getDisciplines(thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getDisciplineApiUrl())
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
const axios = require('axios')
const axios = require('axios');
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getInstituteApiUrl() {
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Institute/'
)
);
}
export class InstituteApi {
public static getInstitutes(thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getInstituteApiUrl())
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
const axios = require('axios')
const axios = require('axios');
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getLicenseApiUrl() {
return 'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/License/'
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/License/'
);
}
export class LicenseApi {
public static getLicenses(thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getLicenseApiUrl())
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
const axios = require('axios')
const axios = require('axios');
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getMetadataApiUrl() {
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Metadata/'
)
);
}
export class MetadataApi {
......@@ -16,7 +16,7 @@ export class MetadataApi {
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(
getMetadataApiUrl() +
......@@ -28,7 +28,7 @@ export class MetadataApi {
version
)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static storeMetadataForFile(
resourceId: string,
......@@ -38,18 +38,18 @@ export class MetadataApi {
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
// remove empty nodes
for (let node in body) {
let property = body[node]
let property = body[node];
if (
property.length === 0 ||
property[0].value === undefined ||
property[0].value === null ||
property[0].value.trim() === ''
) {
delete body[node]
delete body[node];
}
}
......@@ -65,7 +65,7 @@ export class MetadataApi {
body
)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static getApplicationProfile(
projectId: string,
......@@ -73,7 +73,7 @@ export class MetadataApi {
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(
getMetadataApiUrl() +
......@@ -83,7 +83,7 @@ export class MetadataApi {
encodeURIComponent(encodeURIComponent(applicationProfileId))
)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static getApplicationProfileComplete(
resourceId: string,
......@@ -91,7 +91,7 @@ export class MetadataApi {
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(
getMetadataApiUrl() +
......@@ -101,14 +101,14 @@ export class MetadataApi {
encodeURIComponent(encodeURIComponent(applicationProfileId))
)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static listAllApplicationProfiles(projectId: string, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getMetadataApiUrl() + 'project/' + projectId + '/aplist/')
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static getVocabulary(
projectId: string,
......@@ -116,10 +116,10 @@ export class MetadataApi {
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getMetadataApiUrl() + 'vocabulary/' + projectId + '/' + encodeURIComponent(path))
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
const axios = require('axios')
const axios = require('axios');
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getProjectApiUrl() {
return 'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Project/'
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Project/'
);
}
export class ProjectApi {
public static getProjectInformation(projectId: string, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getProjectApiUrl() + projectId)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static storeProject(body: any, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.post(getProjectApiUrl(), body)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static updateProject(projectId: string, body: any, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.post(getProjectApiUrl() + projectId, body)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static getResources(parentId: string, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getProjectApiUrl() + parentId + '/resources')
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static deleteProject(projectId: string, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.delete(getProjectApiUrl() + projectId)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static getProjects(thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getProjectApiUrl())
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
const axios = require('axios')
const axios = require('axios');
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getProjectRoleApiUrl() {
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/ProjectRole/'
)
);
}
export class ProjectRoleApi {
public static getProjectRoles(parentId: string, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getProjectRoleApiUrl() + parentId + '/')
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static getUserRoles(projectId: string, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getProjectRoleApiUrl() + 'project/' + projectId + '/')
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static setProjectRole(body: any, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.post(getProjectRoleApiUrl(), body)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static deleteUser(
parentId: any,
......@@ -37,12 +37,12 @@ export class ProjectRoleApi {
thenHandler: any,
catchHandler: any
) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.delete(
getProjectRoleApiUrl() + 'project/' + parentId + '/user/' + userId + '/role/' + roleId
)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
const axios = require('axios')
const axios = require('axios');
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getResourceApiUrl() {
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Resource/'
)
);
}
export class ResourceApi {
public static getResourceInformation(resourceId: string, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getResourceApiUrl() + resourceId)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static storeResource(parentId: string, body: any, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.post(getResourceApiUrl() + 'Project/' + parentId, body)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static deleteResource(resourceId: string, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.delete(getResourceApiUrl() + resourceId)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static updateResource(resourceId: string, body: any, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.post(getResourceApiUrl() + resourceId, body)
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
const axios = require('axios')
const axios = require('axios');
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getResourceTypeApiUrl() {
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/ResourceType/'
)
);
}
export class ResourceTypeApi {
public static getResourceTypes(thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getResourceTypeApiUrl())
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static getFields(resourceTypeId: any, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getResourceTypeApiUrl() + resourceTypeId + '/fields')
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
const axios = require('axios')
const axios = require('axios');
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getRoleApiUrl() {
return 'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Role/'
return 'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Role/';
}
export class RoleApi {
public static getRoles(thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getRoleApiUrl())
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
const axios = require('axios')
const axios = require('axios');
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getSubProjectApiUrl() {
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/SubProject/'
)
);
}
export class SubProjectApi {
public static getSubProjects(parentId: string, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getSubProjectApiUrl() + parentId + '/')
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
const axios = require('axios')
const axios = require('axios');
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getUserApiUrl() {
return 'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.User/User/'
return 'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.User/User/';
}
export class UserApi {
public static queryUsers(query: string, parentId: string, thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getUserApiUrl() + 'query/' + query + '/project/' + parentId + '/')
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
public static getUser(thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getUserApiUrl() + 'user')
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
const axios = require('axios')
const axios = require('axios');
import apiConnectionBasic from '../basic/api-connection-basic'
import apiConnectionBasic from '../basic/api-connection-basic';
function getVisibilityApiUrl() {
return (
'https://' + apiConnectionBasic.getHostName() + '/coscine/api/Coscine.Api.Project/Visibility/'
)
);
}
export class VisibilityApi {
public static getVisibilities(thenHandler: any, catchHandler: any) {
apiConnectionBasic.setHeader()
apiConnectionBasic.setHeader();
axios
.get(getVisibilityApiUrl())
.then(thenHandler)
.catch(catchHandler)
.catch(catchHandler);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment