Skip to content
This repository has been archived by the owner on Jul 31, 2019. It is now read-only.

Commit

Permalink
Fixed issue that does not work with W-03.
Browse files Browse the repository at this point in the history
  • Loading branch information
tks-abe committed May 30, 2018
1 parent 20af01f commit afdd963
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 41 deletions.
3 changes: 3 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ FlashAir™の無線LAN機能を使い、FlashAir IoT Hubを経由する事で

## Changelog

- [0.3.2](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/tag/v0.3.2)
- W-03で動作しない事がある問題を修正しました。
- iothub.luaの先頭行のバージョン番号が1.5.0未満の場合、最新のLuaスクリプトを[FlashAir IoT Hub](https://iot-hub.flashair-developers.com)からダウンロードしてください。
- [0.3.1](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/tag/v0.3.1)
- OSの言語設定が英語と日本語以外の場合、起動に失敗する問題を修正しました。
- [0.3.0](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/tag/v0.3.0)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ Note: Since version 0.2.0, Lua scripts are using [FlashAir IoT Hub](https://iot-

## Changelog

- [0.3.2](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/tag/v0.3.2)
- Fixed issue that does not work with W-03.
- If the version number of the first line of `iothub.lua` is less than 1.5.0, download the latest Lua script from [FlashAir IoT Hub](https://iot-hub.flashair-developers.com).
- [0.3.1](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/tag/v0.3.1)
- Fixed issue that failed to start if OS locale is other than English and Japanese.
- [0.3.0](https://github.com/FlashAirDevelopers/FlashAirFileManager/releases/tag/v0.3.0)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flashair-file-manager",
"version": "0.3.1",
"version": "0.3.2",
"description": "The application to browse and download files on FlashAir™ via the network.",
"homepage": "https://github.com/FlashAirDevelopers/FlashAirFileManager",
"main": "./src/main/main.js",
Expand Down
3 changes: 2 additions & 1 deletion src/common/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ export const IoTHubApi = {
};
export const FlashAIrScript = {
LIST: '/list_file.lua',
UPLOAD: '/upload_file.lua'
LIST_FETCH_MAX: 10,
UPLOAD: '/upload_file_slim.lua'
};
2 changes: 2 additions & 0 deletions src/common/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const resources = {
filer_label_local_file_date: '更新日付',
filer_label_remote_file_name: '名前',
filer_label_remote_file_date: '更新日付',
filer_label_remote_show_more: '更に表示する',
filer_msg_remote_download_progress: 'ダウンロード中...',
filer_msg_remote_download_completed: 'ダウンロードが完了しました。',
auth_msg_invalid_access_token: '認証処理が失敗しました。再度ログインし直してください。',
Expand All @@ -56,6 +57,7 @@ export const resources = {
filer_label_local_file_date: 'Update date',
filer_label_remote_file_name: 'Name',
filer_label_remote_file_date: 'Update date',
filer_label_remote_show_more: 'Show more',
filer_msg_remote_download_progress: 'Downloading...',
filer_msg_remote_download_completed: 'Download is completed.',
auth_msg_invalid_access_token: 'Authentication processing failed. Please login again.',
Expand Down
10 changes: 8 additions & 2 deletions src/main/store/app-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,21 @@ export class AppStore extends EventEmitter {
/*
* [{
* path:<parent full path>,
* startIndex <Display start index>,
* files:[{
* name:<file name>
* mode:<file type: file, directory>
* size:<file size>
* modification:<file modification timestamp>
* } ...]
* },
* {...}
* ]
*/
localFiles: [],
remoteFiles: [],
// boolean has more remote files
isMoreRemoteFiles: false,
// String current local directory path
localCurDir: os.homedir(),
// String currnent remote direcotry path
Expand Down Expand Up @@ -157,11 +161,12 @@ export class AppStore extends EventEmitter {
this.state.isFetchingRemoteFileList = isFetchingRemoteFileList;
this.emit(AppEvent.CHANGE_FLASHAIR, this.state);
}
_requestFlashAirFileListOnStart({isFetchingRemoteFileList, flashairId, remoteCurDir}) {
_requestFlashAirFileListOnStart({isFetchingRemoteFileList, flashairId, remoteCurDir, isMoreRemoteFiles}) {
this.state.isFetchingRemoteFileList = isFetchingRemoteFileList;
this.state.flashairId = flashairId;
this.state.remoteCurDir = remoteCurDir;
this.state.curJobResponderId = null;
this.state.isMoreRemoteFiles = isMoreRemoteFiles;
this.emit(AppEvent.REQUEST_REMOTE_FILE_LIST, this.state);
}
_requestFlashAirFileListOnSuccess({isFetchingRemoteFileList, curJobResponderId}) {
Expand Down Expand Up @@ -198,9 +203,10 @@ export class AppStore extends EventEmitter {
this.state.message = message;
this.emit(AppEvent.DELETE_REMOTE_JOB_FAILURE);
}
_updateRemoteFileList({remoteFiles, isFetchingRemoteFileList}) {
_updateRemoteFileList({remoteFiles, isFetchingRemoteFileList, isMoreRemoteFiles}) {
this.state.isFetchingRemoteFileList = isFetchingRemoteFileList;
this.state.remoteFiles = remoteFiles;
this.state.isMoreRemoteFiles = isMoreRemoteFiles;
this.emit(AppEvent.UPDATE_REMOTE_FILE_LIST, this.state);
}
_getLocalFileListOnStart({isGetingLocalFileList}) {
Expand Down
18 changes: 12 additions & 6 deletions src/renderer/action/iothub-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,20 @@ export class IoTHubAction {
isFetchingRemoteFileList: false
});
}
requestRemoteFileList(state = {accessToken, isFetchingRemoteFileList, flashairId, remoteCurDir}, useCache = false) {
requestRemoteFileList(state = {accessToken, isFetchingRemoteFileList, flashairId, remoteCurDir, isMoreRemoteFiles}, useCache = false, startIndex = 0) {
if (state.isFetchingRemoteFileList || !state.flashairId) {
return Promise.resolve();
}
return this._requestRemoteFileList(state, useCache);
return this._requestRemoteFileList(state, useCache, startIndex);
}
_requestRemoteFileList(state = {accessToken, isFetchingRemoteFileList, flashairId, remoteCurDir}, useCache = false) {
_requestRemoteFileList(state = {accessToken, isFetchingRemoteFileList, flashairId, remoteCurDir, isMoreRemoteFiles}, useCache, startIndex) {
// Notify fetch start event
this.dispatcher.emit(AppEvent.REQUEST_REMOTE_FILE_LIST, {
isFetchingRemoteFileList: true,
flashairId: state.flashairId,
remoteCurDir: state.remoteCurDir
remoteCurDir: state.remoteCurDir,
remoteFileStartIndex: startIndex || 0,
isMoreRemoteFiles: state.isMoreRemoteFiles
});
const requestBody = {
request: {
Expand All @@ -127,6 +129,9 @@ export class IoTHubAction {
arguments: {current_path: state.remoteCurDir || '/'}
}
};
if (startIndex !== undefined) {
requestBody.request.arguments.start_index = Number(startIndex);
}
return fetch(`${IoTHubApi.baseUrl}${IoTHubApi.jobs.replace('{flashair_id}', state.flashairId)}`, {
method: 'POST',
headers: {
Expand Down Expand Up @@ -251,10 +256,11 @@ export class IoTHubAction {
});
});
}
updateFiles(state = {remoteFiles}) {
updateFiles(state = {remoteFiles, isMoreRemoteFiles}) {
this.dispatcher.emit(AppEvent.UPDATE_REMOTE_FILE_LIST, {
remoteFiles: state.remoteFiles,
isFetchingRemoteFileList: false
isFetchingRemoteFileList: false,
isMoreRemoteFiles: state.isMoreRemoteFiles
});
}
selectRemoteFile(fileName) {
Expand Down
110 changes: 82 additions & 28 deletions src/renderer/view/filer.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ export class FilerPage {
if (tmpRemoteFiles && tmpRemoteFiles.files) {
templateVar.remoteFiles = tmpRemoteFiles.files;
}
// Set fetch more files start index
templateVar.remoteStartIndex = tmpRemoteFiles.startIndex;
}
this._templateAddFileFlag(templateVar);
const renderContent = filerTemplate(templateVar || this.baseTemplateVar);
Expand Down Expand Up @@ -350,6 +352,10 @@ export class FilerPage {
$('#remote-reload').on('click', this.refreshRemoteDirectory);
$('#local-reload').on('click', this.refreshLocalDirectory);
$('#download-button').on('click', this.onClickDownload);
$('#remote-file-row-more-item').on('click', (event) => {
const startIndex = $(event.currentTarget).attr('data-start-index');
this.onClickMoreRemoteFiles(startIndex);
});

// Show FlashAir file loading
if (templateVar.isFetchingFlashairs || templateVar.isFetchingRemoteFileList) {
Expand Down Expand Up @@ -411,7 +417,11 @@ export class FilerPage {
}
changeRemoteDirecory(remoteNextDir, useCache) {
this.iotHubAction.requestRemoteFileList(Object.assign(
appMain.store.getState(), {remoteCurDir: remoteNextDir, selectedRemoteFile: null}
appMain.store.getState(), {
remoteCurDir: remoteNextDir,
selectedRemoteFile: null,
isMoreRemoteFiles: false
}
,useCache)
)
.catch(response => {
Expand Down Expand Up @@ -480,6 +490,15 @@ export class FilerPage {
}
});
}
onClickMoreRemoteFiles(startIndex) {
this.iotHubAction.requestRemoteFileList(appMain.store.getState(), true, startIndex)
.catch(response => {
log.error(response);
if (response) {
this.notifyMessage('danger', resources[this.locale].common_msg_process_failure);
}
});
}
watchRequestJob() {
const curState = appMain.store.getState();
this.iotHubAction.getJobs(curState)
Expand Down Expand Up @@ -533,6 +552,31 @@ export class FilerPage {
}
}
}
_comparetorFiles(a, b) {
// sort by mode(directory or file)
// directory than file
if (a.m < b.m) {
return -1;
} else if (b.m < a.m) {
return 1;
}
// sort by name
if (a.n.hasOwnProperty('localeCompare')) {
const nameCmp = a.n.localeCompare(b.n);
if (nameCmp !== 0) {
// ASC sort
return nameCmp;
}
}
// ASC sort
if (a.n < b.n) {
return -1;
} else if (b.n < a.n) {
return 1;
}
// sort by timestamp
return a.u - b.u;
}
_fetchRemoteFileList(job) {
const curState = appMain.store.getState();
if ((job.response)
Expand All @@ -542,49 +586,59 @@ export class FilerPage {
let fetchedDir = curRemoteFiles.filter(dir => {
return dir.path !== job.request.arguments.current_path;
});
job.response.result.sort((a, b) => {
// sort by mode(directory or file)
// directory than file
if (a.m < b.m) {
return -1;
} else if (b.m < a.m) {
return 1;
}
// sort by name
if (a.n.hasOwnProperty('localeCompare')) {
const nameCmp = a.n.localeCompare(b.n);
if (nameCmp !== 0) {
// ASC sort
return nameCmp;
}
}
// ASC sort
if (a.n < b.n) {
return -1;
} else if (b.n < a.n) {
return 1;
}
// sort by timestamp
return a.u - b.u;
let prevDir = curRemoteFiles.filter(dir => {
return dir.path === job.request.arguments.current_path;
});
if (prevDir.length > 0) {
prevDir = prevDir[0];
} else {
prevDir = null;
}
job.response.result.forEach((file, index, array) => {
// Mapping shot protperty to regureler property
array[index].name = file.n;
array[index].mode = file.m;
// formatting modification timestamp
array[index].modification = dateFormat.format(fatDateToDate(file.u), 'yyyy/MM/dd');
});

let nextFiles = job.response.result;
let isMoreFiles = false;
// Cut fetch size
if (nextFiles.length > FlashAIrScript.LIST_FETCH_MAX) {
nextFiles = nextFiles.slice(0, FlashAIrScript.LIST_FETCH_MAX);
isMoreFiles = true;
}
// Add previous directory items
if (prevDir && prevDir.startIndex > 0) {
nextFiles = prevDir.files.concat(nextFiles);
// Remove parent directory item
nextFiles.shift();
// Merge and Uniq
const newFileMap = new Map();
nextFiles.forEach(file => newFileMap.set(file.name, file));
nextFiles.length = 0;
for (let file of newFileMap.values()) {
nextFiles.push(file);
}
}
let remoteFileStartIndex = nextFiles.length;
nextFiles.sort(this._comparetorFiles);
// Add move parent directory item
job.response.result.unshift({
nextFiles.unshift({
name: Filer.files.special.PARENT_DIR,
mode: Filer.files.mode.DIRECTORY,
modification: ''
});
fetchedDir = fetchedDir.concat([{
path: job.request.arguments.current_path,
files: job.response.result
startIndex: remoteFileStartIndex,
files: nextFiles
}]);
this.iotHubAction.updateFiles({remoteFiles: fetchedDir});
this.iotHubAction.updateFiles({
remoteFiles: fetchedDir,
isMoreRemoteFiles: isMoreFiles
});
this.iotHubAction.deleteJob(curState, job)
.catch(message => {
log.error(message);
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/view/filer_tmpl.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<td class="col-xs-3" id="remote-file-modification-{{name}}">{{modification}}</td>
</tr>
{{/each}}
{{#if isMoreRemoteFiles}}
<tr id="remote-file-row-more-item" data-start-index="{{remoteStartIndex}}">
<td class="col-xs-12 more-item">{{filer_label_remote_show_more}}</td>
</tr>
{{/if}}
</tbody>
</table>
</div>
Expand Down
10 changes: 7 additions & 3 deletions static/css/file-manager.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
}
.remote-files td:nth-child(2),
.local-files td:nth-child(2) {
text-overflow:ellipsis;
overflow:hidden;
white-space:nowrap;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.remote-files .more-item {
cursor: pointer;
text-align: center;
}

.fa-dir-button {
Expand Down

0 comments on commit afdd963

Please sign in to comment.