Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
(Merge branch 'refs/heads/v0.5.0')
Browse files Browse the repository at this point in the history
### Version 0.5.0

#### Features
- Add Clean (Resources) tray button
- Sort revisions in descending order
- Add basic edit functions (Copy/Paste)

#### Fixes
- Fix downloaded status if user has used Clean
- Close eventSource on error or if making a new eventSource (due to login or switching page)
- Fix missing name from metadata.xml bug (a.k.a loading_metadata)
  • Loading branch information
ericpyle committed May 25, 2018
2 parents ddf2115 + 71a1b2a commit 5817940
Show file tree
Hide file tree
Showing 11 changed files with 330 additions and 110 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
### Version 0.5.0

#### Features
- Add Clean (Resources) tray button
- Sort revisions in descending order
- Add basic edit functions (Copy/Paste)

#### Fixes
- Fix downloaded status if user has used Clean
- Close eventSource on error or if making a new eventSource (due to login or switching page)
- Fix missing name from metadata.xml bug (a.k.a loading_metadata)

### Version 0.4.2

#### Fixes
Expand Down
74 changes: 71 additions & 3 deletions app/actions/bundle.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const bundleActions = {
setupBundlesEventSource,
downloadResources,
requestSaveBundleTo,
removeResources,
toggleModePauseResume,
toggleSelectBundle
};
Expand Down Expand Up @@ -44,7 +45,7 @@ export function fetchAll() {
return bundleService
.fetchAll()
.then(
bundles => dispatch(success(sort(bundles).asc([b => b.name]))),
bundles => dispatch(success(sort(bundles).asc([b => b.name, b => (1 / b.revision)]))),
error => dispatch(failure(error))
);
};
Expand Down Expand Up @@ -73,29 +74,61 @@ export function setupBundlesEventSource(authentication) {
eventSource.onerror = (error) => {
console.log('EventSource failed.');
console.log(error);
eventSource.close();
};
const listeners = {
'storer/execute_task': listenStorerExecuteTaskDownloadResources,
'storer/change_mode': (e) => listenStorerChangeMode(e, dispatch),
'downloader/receiver': listenDownloaderReceiver,
'downloader/status': (e) => listenDownloaderStatus(e, dispatch),
'storer/delete_resource': (e) => listenStorerDeleteResource(e, dispatch),
'storer/update_from_download': listenStorerUpdateFromDownload,
};
Object.keys(listeners).forEach((evType) => {
const handler = listeners[evType];
eventSource.addEventListener(evType, handler);
});
dispatch(connectedToSessionEvents(eventSource, authentication));

function connectedToSessionEvents(_eventSource, _authentication) {
return {
type: bundleConstants.SESSION_EVENTS_CONNECTED,
eventSource: _eventSource,
authentication: _authentication
};
}
};

function listenStorerExecuteTaskDownloadResources(e) {
console.log(e);
}

function listenStorerChangeMode(e, dispatch) {
console.log(e);
const data = JSON.parse(e.data);
const bundleId = data.args[0];
const mode = data.args[1];
if (mode === 'store') {
dispatch(updateStatus(bundleId, 'COMPLETED'));
}
}

function updateStatus(_id, status) {
return {
type: bundleConstants.UPDATE_STATUS,
id: _id,
status,
};
}

function listenDownloaderReceiver(e) {
console.log(e);
}

/* downloader/status
* {'event': 'downloader/status', 'data': {'args': ('48a8e8fe-76ac-45d6-9b3a-d7d99ead7224', 4, 8), 'component': 'downloader', 'type': 'status'}}
* {'event': 'downloader/status',
* 'data': {'args': ('48a8e8fe-76ac-45d6-9b3a-d7d99ead7224', 4, 8),
* 'component': 'downloader', 'type': 'status'}}
*/
function listenDownloaderStatus(e, dispatch) {
console.log(e);
Expand All @@ -115,6 +148,22 @@ export function setupBundlesEventSource(authentication) {
};
}

function listenStorerDeleteResource(e, dispatch) {
console.log(e);
const data = JSON.parse(e.data);
const bundleId = data.args[0];
const resourceToRemove = data.args[1];
dispatch(updateRemoveResourcesStatus(bundleId, resourceToRemove));
}

function updateRemoveResourcesStatus(_id, resourceToRemove) {
return {
type: bundleConstants.REMOVE_RESOURCES_UPDATED,
id: _id,
resourceToRemove
};
}

function listenStorerUpdateFromDownload(e) {
console.log(e);
}
Expand All @@ -140,6 +189,24 @@ export function downloadResources(id) {
}
}

export function removeResources(id) {
return async dispatch => {
try {
const resourcePathsToRemove = await bundleService.getResourcePaths(id);
dispatch(request(id, resourcePathsToRemove));
await bundleService.removeResources(id);
} catch (error) {
dispatch(failure(id, error));
}
};
function request(_id, resourcesToRemove) {
return { type: bundleConstants.REMOVE_RESOURCES_REQUEST, id: _id, resourcesToRemove };
}
function failure(_id, error) {
return { type: bundleConstants.REMOVE_RESOURCES_FAILURE, id, error };
}
}

function removeBundle(id) {
return dispatch => {
dispatch(request(id));
Expand Down Expand Up @@ -341,7 +408,8 @@ function getMockBundles() {
// const taskOrder = ['UPLOAD', 'DOWNLOAD', 'SAVETO'];
// const statusOrder = ['IN_PROGRESS', 'DRAFT', 'COMPLETED', 'NOT_STARTED'];
const sortedBundles = sort(bundles).asc([
b => b.name
b => b.name,
b => (1 / b.revision),
]);
return sortedBundles;
}
54 changes: 43 additions & 11 deletions app/components/Bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import CallSplit from 'material-ui/svg-icons/communication/call-split';
import ActionInfo from 'material-ui/svg-icons/action/info';
import ActionDelete from 'material-ui/svg-icons/action/delete';
import { navigationConstants } from '../constants/navigation.constants';
import { mockFetchAll, fetchAll, toggleSelectBundle, toggleModePauseResume, setupBundlesEventSource, downloadResources, requestSaveBundleTo } from '../actions/bundle.actions';
import { mockFetchAll, fetchAll,
toggleSelectBundle, toggleModePauseResume,
setupBundlesEventSource, downloadResources, requestSaveBundleTo,
removeResources } from '../actions/bundle.actions';
import { updateSearchInput, clearSearch } from '../actions/bundleFilter.actions';
import styles from './Bundles.css';

Expand All @@ -25,6 +28,7 @@ type Props = {
downloadResources: () => {},
setupBundlesEventSource: () => {},
requestSaveBundleTo: () => {},
removeResources: () => {},
toggleSelectBundle: () => {},
toggleModePauseResume: () => {},
updateSearchInput: () => {},
Expand Down Expand Up @@ -52,6 +56,7 @@ const mapDispatchToProps = {
setupBundlesEventSource,
downloadResources,
requestSaveBundleTo,
removeResources,
toggleSelectBundle,
toggleModePauseResume,
updateSearchInput,
Expand All @@ -71,13 +76,22 @@ class Bundles extends Component<Props> {
// clear search results on location change
clearSearchResults();
});
console.log('Bundles Did mount');
console.log('Bundles did mount');
const { authentication } = this.props;
if (authentication.user) {
this.props.setupBundlesEventSource(authentication);
}
}

componentWillUnmount() {
const { bundles } = this.props;
console.log('Bundles did unmount');
if (bundles.eventSource) {
bundles.eventSource.close();
console.log('bundles EventSource closed');
}
}

onKeyPress(event, bundleId) {
if (['Enter', ' '].includes(event.key)) {
this.onClickBundleRow(event, bundleId);
Expand Down Expand Up @@ -110,6 +124,11 @@ class Bundles extends Component<Props> {
event.stopPropagation();
}

onClickRemoveResources(event, bundle) {
this.props.removeResources(bundle.id);
event.stopPropagation();
}

onClickTogglePauseResume(event, bundleId) {
this.props.toggleModePauseResume(bundleId);
event.stopPropagation();
Expand Down Expand Up @@ -188,11 +207,11 @@ class Bundles extends Component<Props> {
onClick={(e) => openInFolder(e, d, savedToHistory)}
/>)
}
{(d.task === 'UPLOAD' || d.task === 'DOWNLOAD') && (d.status === 'COMPLETED' || d.status === 'DRAFT' || d.status === 'IN_PROGRESS') &&
{showStatusAsText(d) &&
<div style={{ paddingRight: '20px', paddingTop: '6px' }}>
<Highlighter textToHighlight={d.displayAs.status} {...highlighterSharedProps(d)} />
</div>}
{d.task === 'DOWNLOAD' && d.status === 'NOT_STARTED' &&
{showDownloadButton(d) &&
<FlatButton
labelPosition="before"
label={<Highlighter textToHighlight={d.displayAs.status} {...highlighterSharedProps(d)} />}
Expand All @@ -217,10 +236,9 @@ class Bundles extends Component<Props> {
/>
<FlatButton
label="Save To"
disabled={((d.isDownloaded === undefined || !d.isDownloaded) || (d.progress && d.progress < 100)) === true}
disabled={hasNotYetDownloadedResources(d)}
icon={<SaveTo />}
onKeyPress={(e) => this.startSaveBundleTo(e, d, savedToHistory)}
onClick={(e) => this.startSaveBundleTo(e, d, savedToHistory)}
{...onClickAndKeyPressProps((e) => this.startSaveBundleTo(e, d, savedToHistory))}
/>
<FlatButton
label="Info"
Expand All @@ -229,11 +247,10 @@ class Bundles extends Component<Props> {
{...onClickAndKeyPressProps((e) => onOpenLink(e, `https://thedigitalbiblelibrary.org/entry?id=${d.dblId}`))}
/>
<FlatButton
label="Delete"
disabled
label="Clean"
disabled={hasNotYetDownloadedResources(d)}
icon={<ActionDelete />}
onKeyPress={(e) => stopPropagation(e)}
onClick={(e) => stopPropagation(e)}
{...onClickAndKeyPressProps((e) => this.onClickRemoveResources(e, d))}
/>
</div>
}
Expand All @@ -248,6 +265,21 @@ export default connect(
mapDispatchToProps,
)(Bundles);

function hasNotYetDownloadedResources(bundle) {
return ((bundle.isDownloaded === undefined || !bundle.isDownloaded)
|| (bundle.progress && bundle.progress < 100)) === true;
}

function showStatusAsText(bundle) {
return ((bundle.task === 'UPLOAD' || bundle.task === 'DOWNLOAD') &&
(bundle.status === 'COMPLETED' || bundle.status === 'DRAFT' || bundle.status === 'IN_PROGRESS')) ||
((bundle.task === 'REMOVE_RESOURCES') && bundle.status === 'IN_PROGRESS');
}

function showDownloadButton(bundle) {
return (bundle.task === 'DOWNLOAD' && bundle.status === 'NOT_STARTED');
}

function displayRow(bundlesFilter, bundle) {
return !(bundlesFilter.isSearchActive) ||
bundle.id in bundlesFilter.searchResults.bundlesMatching;
Expand Down
8 changes: 8 additions & 0 deletions app/constants/bundle.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ export const bundleConstants = {
DELETE_SUCCESS: 'BUNDLES_DELETE_SUCCESS',
DELETE_FAILURE: 'BUNDLES_DELETE_FAILURE',

UPDATE_STATUS: 'BUNDLES_UPDATE_STATUS',

SESSION_EVENTS_CONNECTED: 'BUNDLES_SESSION_EVENTS_CONNECTED',

DOWNLOAD_RESOURCES_REQUEST: 'BUNDLES_DOWNLOAD_RESOURCES_REQUEST',
DOWNLOAD_RESOURCES_UPDATED: 'BUNDLES_DOWNLOAD_RESOURCES_UPDATED',
DOWNLOAD_RESOURCES_FAILURE: 'BUNDLES_DOWNLOAD_RESOURCES_FAILURE',

REMOVE_RESOURCES_REQUEST: 'BUNDLES_REMOVE_RESOURCES_REQUEST',
REMOVE_RESOURCES_UPDATED: 'BUNDLES_REMOVE_RESOURCES_UPDATED',
REMOVE_RESOURCES_FAILURE: 'BUNDLES_REMOVE_RESOURCES_FAILURE',

SAVETO_REQUEST: 'BUNDLES_SAVETO_REQUEST',
SAVETO_UPDATED: 'BUNDLES_SAVETO_UPDATED',
SAVETO_SUCCESS: 'BUNDLES_SAVETO_SUCCESS',
Expand Down
Loading

0 comments on commit 5817940

Please sign in to comment.