2016-02-25 12:31:21 -08:00
|
|
|
import AuthenticationPage from './AuthenticationPage';
|
2016-08-24 21:36:44 -03:00
|
|
|
import { createEntry } from '../../valueObjects/Entry';
|
2016-02-25 12:31:21 -08:00
|
|
|
|
2016-02-25 20:40:35 -08:00
|
|
|
function getSlug(path) {
|
2016-05-30 16:55:32 -07:00
|
|
|
const m = path.match(/([^\/]+?)(\.[^\/\.]+)?$/);
|
2016-02-25 20:40:35 -08:00
|
|
|
return m && m[1];
|
|
|
|
}
|
|
|
|
|
2016-02-25 12:31:21 -08:00
|
|
|
export default class TestRepo {
|
|
|
|
constructor(config) {
|
|
|
|
this.config = config;
|
2016-02-25 20:40:35 -08:00
|
|
|
if (window.repoFiles == null) {
|
|
|
|
throw 'The TestRepo backend needs a "window.repoFiles" object.';
|
|
|
|
}
|
2016-02-25 12:31:21 -08:00
|
|
|
}
|
|
|
|
|
2016-06-05 01:52:18 -07:00
|
|
|
setUser() {}
|
|
|
|
|
2016-02-25 12:31:21 -08:00
|
|
|
authComponent() {
|
|
|
|
return AuthenticationPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
authenticate(state) {
|
2016-07-19 19:42:37 -03:00
|
|
|
return Promise.resolve({ email: state.email });
|
2016-02-25 12:31:21 -08:00
|
|
|
}
|
2016-02-25 20:40:35 -08:00
|
|
|
|
|
|
|
entries(collection) {
|
|
|
|
const entries = [];
|
|
|
|
const folder = collection.get('folder');
|
|
|
|
if (folder) {
|
|
|
|
for (var path in window.repoFiles[folder]) {
|
2016-08-24 21:36:44 -03:00
|
|
|
entries.push(createEntry(folder + '/' + path, getSlug(path), window.repoFiles[folder][path].content));
|
2016-02-25 20:40:35 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-05 01:52:18 -07:00
|
|
|
return Promise.resolve({
|
|
|
|
pagination: {},
|
|
|
|
entries
|
|
|
|
});
|
2016-02-25 20:40:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
entry(collection, slug) {
|
2016-06-05 01:52:18 -07:00
|
|
|
return this.entries(collection).then((response) => (
|
|
|
|
response.entries.filter((entry) => entry.slug === slug)[0]
|
2016-05-30 16:55:32 -07:00
|
|
|
));
|
2016-02-25 20:40:35 -08:00
|
|
|
}
|
2016-06-06 21:53:22 -03:00
|
|
|
|
2016-08-29 17:09:04 -03:00
|
|
|
persistEntry(entry, mediaFiles = [], options) {
|
|
|
|
const newEntry = options.newEntry || false;
|
2016-07-19 17:11:22 -03:00
|
|
|
const folder = entry.path.substring(0, entry.path.lastIndexOf('/'));
|
2016-06-10 00:16:01 -03:00
|
|
|
const fileName = entry.path.substring(entry.path.lastIndexOf('/') + 1);
|
2016-08-25 16:11:00 -03:00
|
|
|
if (newEntry) {
|
|
|
|
window.repoFiles[folder][fileName] = { content: entry.raw };
|
|
|
|
} else {
|
|
|
|
window.repoFiles[folder][fileName]['content'] = entry.raw;
|
|
|
|
}
|
2016-07-19 19:42:37 -03:00
|
|
|
mediaFiles.forEach(media => media.uploaded = true);
|
|
|
|
return Promise.resolve();
|
2016-06-06 21:53:22 -03:00
|
|
|
}
|
2016-09-06 13:04:17 -03:00
|
|
|
|
2016-02-25 12:31:21 -08:00
|
|
|
}
|