[add] (view) add ImageDataList
This commit is contained in:
@@ -89,17 +89,10 @@ import ru.m.puzzlez.view.popup.PreviewPopup;
|
||||
}
|
||||
|
||||
private function back():Void {
|
||||
(if (game != null && game.state.status == COMPLETE) {
|
||||
Promise.promise(true);
|
||||
} else {
|
||||
ConfirmView.confirm("Exit?");
|
||||
}).then(result -> {
|
||||
(game.state.status == COMPLETE ? Promise.promise(true) : ConfirmView.confirm("Exit?"))
|
||||
.then(result -> {
|
||||
if (result) {
|
||||
if (game.state.status == COMPLETE) {
|
||||
switcher.change(GameListFrame.ID, COMPLETE);
|
||||
} else {
|
||||
switcher.back();
|
||||
}
|
||||
switcher.change(GameListFrame.ID, game.state.status);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,83 +1,29 @@
|
||||
package ru.m.puzzlez.view;
|
||||
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.form.ToggleButtonView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.popup.ConfirmView;
|
||||
import ru.m.data.IDataSource;
|
||||
import ru.m.puzzlez.core.GameState;
|
||||
import ru.m.puzzlez.core.Id.ImageId;
|
||||
import ru.m.puzzlez.storage.GameStorage;
|
||||
import ru.m.puzzlez.view.common.PaginatorView;
|
||||
import ru.m.puzzlez.view.PuzzleImageView;
|
||||
import ru.m.puzzlez.view.common.ImageDataList;
|
||||
|
||||
@:template class GameListFrame extends FrameView<GameStatus> {
|
||||
|
||||
public static var ID(default, never) = "game_list";
|
||||
|
||||
@:view("images") var imagesView:ActionDataView<ImageId, PuzzleImageView, Action>;
|
||||
@:view("pages") var pagesView:PaginatorView;
|
||||
private var loading:LoadingWrapper;
|
||||
@:view("images") var imagesView:ImageDataList;
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var storage:GameStorage;
|
||||
|
||||
private var status:GameStatus;
|
||||
private var page:Page;
|
||||
|
||||
private var data(default, set):DataPage<ImageId>;
|
||||
|
||||
private function set_data(value:DataPage<ImageId>):DataPage<ImageId> {
|
||||
data = value;
|
||||
imagesView.data = data.data;
|
||||
pagesView.page = value;
|
||||
return data;
|
||||
}
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
loading = new LoadingWrapper(imagesView);
|
||||
page = {index: 0, count: 6, order: [{key: "date", reverse: true}]};
|
||||
}
|
||||
|
||||
private function pageFactory(index:Int, value:Int):ToggleButtonView {
|
||||
var result = new ToggleButtonView();
|
||||
result.text = '${value}';
|
||||
result.on = data.page.index == value;
|
||||
return result;
|
||||
imagesView.source = storage;
|
||||
}
|
||||
|
||||
override public function onShow(data:GameStatus):Void {
|
||||
page.index = 0;
|
||||
this.data = {
|
||||
page: page,
|
||||
total: 0,
|
||||
data: [],
|
||||
};
|
||||
status = data;
|
||||
page.filter = ["status" => status];
|
||||
refresh();
|
||||
}
|
||||
|
||||
private function start(id:ImageId):Void {
|
||||
storage.get(id).then(state -> switcher.change(GameFrame.ID, state));
|
||||
}
|
||||
|
||||
private function refresh():Void {
|
||||
loading.promise = storage.getIndexPage(page).then(data -> this.data = data);
|
||||
}
|
||||
|
||||
private function onAction(imageId:ImageId, action:Action):Void {
|
||||
switch action {
|
||||
case CLEAN:
|
||||
ConfirmView.confirm("Delete state?").then(result -> {
|
||||
if (result) {
|
||||
storage.delete(imageId).then(_ -> refresh());
|
||||
}
|
||||
});
|
||||
case _:
|
||||
}
|
||||
imagesView.reset();
|
||||
imagesView.page.filter = ["status" => data];
|
||||
imagesView.refresh();
|
||||
}
|
||||
|
||||
private function back():Void {
|
||||
|
||||
@@ -2,26 +2,8 @@
|
||||
style: frame
|
||||
views:
|
||||
- id: images
|
||||
$type: haxework.view.data.ActionDataView
|
||||
layout:
|
||||
$type: haxework.view.layout.TailLayout
|
||||
rowSize: 3
|
||||
margin: 5
|
||||
vAlign: middle
|
||||
$type: ru.m.puzzlez.view.common.ImageDataList
|
||||
geometry.stretch: true
|
||||
factory: ~ru.m.puzzlez.view.PuzzleImageView.factory
|
||||
+onDataSelect: ~start
|
||||
+onDataAction: ~onAction
|
||||
geometry.margin: 5
|
||||
overflow.y: scroll
|
||||
- id: pages
|
||||
$type: ru.m.puzzlez.view.common.PaginatorView
|
||||
geometry.width: 100%
|
||||
+onPageSelect: |
|
||||
~(index) -> {
|
||||
page.index = index;
|
||||
refresh();
|
||||
}
|
||||
- $type: haxework.view.form.ButtonView
|
||||
text: Back
|
||||
geometry.position: absolute
|
||||
|
||||
@@ -1,110 +1,40 @@
|
||||
package ru.m.puzzlez.view;
|
||||
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.form.ButtonView;
|
||||
import haxework.view.form.ToggleButtonView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.frame.FrameView;
|
||||
import haxework.view.popup.ConfirmView;
|
||||
import ru.m.data.IDataSource;
|
||||
import ru.m.puzzlez.core.Id;
|
||||
import ru.m.puzzlez.FileUtil;
|
||||
import ru.m.puzzlez.source.FileSource;
|
||||
import ru.m.puzzlez.storage.GameStorage;
|
||||
import ru.m.puzzlez.storage.ImageStorage;
|
||||
import ru.m.puzzlez.view.common.PaginatorView;
|
||||
import ru.m.puzzlez.view.PuzzleImageView;
|
||||
import ru.m.puzzlez.view.common.ImageDataList;
|
||||
|
||||
@:template class ImageListFrame extends FrameView<ImageListSource> {
|
||||
public static var ID = "image_list";
|
||||
|
||||
@:view("images") var imagesView:ActionDataView<ImageId, PuzzleImageView, Action>;
|
||||
@:view("pages") var pagesView:PaginatorView;
|
||||
@:view("images") var imagesView:ImageDataList;
|
||||
@:view var select:ButtonView;
|
||||
|
||||
@:provide var imageStorage:ImageStorage;
|
||||
@:provide var gameStorage:GameStorage;
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
|
||||
private var source:ImageListSource;
|
||||
private var loading:LoadingWrapper;
|
||||
|
||||
private var page:Page;
|
||||
private var data(default, set):DataPage<ImageId>;
|
||||
|
||||
private function set_data(value:DataPage<ImageId>):DataPage<ImageId> {
|
||||
data = value;
|
||||
imagesView.data = data.data;
|
||||
pagesView.page = data;
|
||||
return data;
|
||||
}
|
||||
|
||||
public function new() {
|
||||
super(ID);
|
||||
page = {index: 0, count: 6, order: [{key: "date", reverse: true}]};
|
||||
loading = new LoadingWrapper(imagesView);
|
||||
}
|
||||
|
||||
private function pageFactory(index:Int, value:Int):ToggleButtonView {
|
||||
var result = new ToggleButtonView();
|
||||
result.text = '${value}';
|
||||
result.on = data.page.index == value;
|
||||
return result;
|
||||
}
|
||||
|
||||
override public function onShow(data:ImageListSource):Void {
|
||||
page.index = 0;
|
||||
this.data = {
|
||||
page: page,
|
||||
total: 0,
|
||||
data: [],
|
||||
};
|
||||
imagesView.reset();
|
||||
if (data != null) {
|
||||
source = data;
|
||||
select.visible = source.source.id == FileSource.ID;
|
||||
page.filter = ["type" => data.type];
|
||||
refresh();
|
||||
select.visible = data.source.id == FileSource.ID;
|
||||
imagesView.page.filter = ["type" => data.type];
|
||||
imagesView.source = data.source;
|
||||
imagesView.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private function selectFile():Void {
|
||||
FileUtil.browse().then((data:FileContent) -> {
|
||||
var fileSource:FileSource = cast source.source;
|
||||
fileSource.append(data.content).then(_ -> refresh());
|
||||
});
|
||||
}
|
||||
|
||||
private function onAction(imageId:ImageId, action:Action):Void {
|
||||
switch action {
|
||||
case REMOVE:
|
||||
var fileSource:FileSource = Std.instance(source.source, FileSource);
|
||||
if (fileSource != null) {
|
||||
ConfirmView.confirm("Delete image?").then(result -> {
|
||||
if (result) {
|
||||
fileSource.remove(imageId).then(_ -> refresh());
|
||||
}
|
||||
});
|
||||
}
|
||||
case CLEAN:
|
||||
ConfirmView.confirm("Delete state?").then(result -> {
|
||||
if (result) {
|
||||
gameStorage.delete(imageId).then(_ -> refresh());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private function refresh():Void {
|
||||
loading.promise = source.source.getIndexPage(page).then(data -> this.data = data);
|
||||
}
|
||||
|
||||
private function start(imageId:ImageId):Void {
|
||||
gameStorage.get(imageId).then(state -> {
|
||||
if (state != null) {
|
||||
switcher.change(GameFrame.ID, state);
|
||||
} else {
|
||||
switcher.change(PresetFrame.ID, imageId);
|
||||
}
|
||||
var fileSource:FileSource = cast imageStorage.sources.get(FileSource.ID);
|
||||
fileSource.append(data.content).then(_ -> imagesView.refresh());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,26 +2,8 @@
|
||||
style: frame
|
||||
views:
|
||||
- id: images
|
||||
$type: haxework.view.data.ActionDataView
|
||||
layout:
|
||||
$type: haxework.view.layout.TailLayout
|
||||
rowSize: 3
|
||||
margin: 5
|
||||
vAlign: middle
|
||||
$type: ru.m.puzzlez.view.common.ImageDataList
|
||||
geometry.stretch: true
|
||||
factory: ~ru.m.puzzlez.view.PuzzleImageView.factory
|
||||
+onDataSelect: ~start
|
||||
+onDataAction: ~onAction
|
||||
geometry.margin: 5
|
||||
overflow.y: scroll
|
||||
- id: pages
|
||||
$type: ru.m.puzzlez.view.common.PaginatorView
|
||||
geometry.width: 100%
|
||||
+onPageSelect: |
|
||||
~(index) -> {
|
||||
page.index = index;
|
||||
refresh();
|
||||
}
|
||||
- id: select
|
||||
$type: haxework.view.form.ButtonView
|
||||
text: Select...
|
||||
|
||||
92
src/haxe/ru/m/puzzlez/view/common/ImageDataList.hx
Normal file
92
src/haxe/ru/m/puzzlez/view/common/ImageDataList.hx
Normal file
@@ -0,0 +1,92 @@
|
||||
package ru.m.puzzlez.view.common;
|
||||
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.form.ToggleButtonView;
|
||||
import haxework.view.frame.FrameSwitcher;
|
||||
import haxework.view.group.VGroupView;
|
||||
import haxework.view.popup.ConfirmView;
|
||||
import ru.m.data.IDataSource;
|
||||
import ru.m.puzzlez.core.Id;
|
||||
import ru.m.puzzlez.source.FileSource;
|
||||
import ru.m.puzzlez.storage.GameStorage;
|
||||
import ru.m.puzzlez.storage.ImageStorage;
|
||||
import ru.m.puzzlez.view.common.PuzzleImageView;
|
||||
|
||||
@:template class ImageDataList extends VGroupView {
|
||||
|
||||
public var source:IDataIndex<ImageId>;
|
||||
public var page:Page;
|
||||
|
||||
@:view("images") var imagesView:ActionDataView<ImageId, PuzzleImageView, Action>;
|
||||
@:view("paginator") var paginatorView:PaginatorView;
|
||||
private var loading:LoadingWrapper;
|
||||
|
||||
@:provide var switcher:FrameSwitcher;
|
||||
@:provide var gameStorage:GameStorage;
|
||||
@:provide var imageStorage:ImageStorage;
|
||||
|
||||
public var data(default, set):DataPage<ImageId>;
|
||||
|
||||
private function set_data(value:DataPage<ImageId>):DataPage<ImageId> {
|
||||
data = value;
|
||||
imagesView.data = data.data;
|
||||
paginatorView.page = data;
|
||||
return data;
|
||||
}
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
loading = new LoadingWrapper(imagesView);
|
||||
page = {index: 0, count: 6, order: [{key: "date", reverse: true}]};
|
||||
}
|
||||
|
||||
private function pageFactory(index:Int, value:Int):ToggleButtonView {
|
||||
var result = new ToggleButtonView();
|
||||
result.text = '${value}';
|
||||
result.on = data.page.index == value;
|
||||
return result;
|
||||
}
|
||||
|
||||
private function start(imageId:ImageId):Void {
|
||||
gameStorage.get(imageId).then(state -> {
|
||||
if (state != null) {
|
||||
switcher.change(GameFrame.ID, state);
|
||||
} else {
|
||||
switcher.change(PresetFrame.ID, imageId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function onAction(imageId:ImageId, action:Action):Void {
|
||||
switch action {
|
||||
case REMOVE:
|
||||
var fileSource:FileSource = cast imageStorage.sources.get(FileSource.ID);
|
||||
if (fileSource != null) {
|
||||
ConfirmView.confirm("Delete image?").then(result -> {
|
||||
if (result) {
|
||||
fileSource.remove(imageId).then(_ -> refresh());
|
||||
}
|
||||
});
|
||||
}
|
||||
case CLEAN:
|
||||
ConfirmView.confirm("Delete state?").then(result -> {
|
||||
if (result) {
|
||||
gameStorage.delete(imageId).then(_ -> refresh());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function refresh():Void {
|
||||
loading.promise = source.getIndexPage(page).then(data -> this.data = data);
|
||||
}
|
||||
|
||||
public function reset():Void {
|
||||
page.index = 0;
|
||||
data = {
|
||||
page: page,
|
||||
total: 0,
|
||||
data: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
23
src/haxe/ru/m/puzzlez/view/common/ImageDataList.yaml
Normal file
23
src/haxe/ru/m/puzzlez/view/common/ImageDataList.yaml
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
views:
|
||||
- id: images
|
||||
$type: haxework.view.data.ActionDataView
|
||||
layout:
|
||||
$type: haxework.view.layout.TailLayout
|
||||
rowSize: 3
|
||||
margin: 5
|
||||
vAlign: middle
|
||||
geometry.stretch: true
|
||||
factory: ~ru.m.puzzlez.view.common.PuzzleImageView.factory
|
||||
+onDataSelect: ~start
|
||||
+onDataAction: ~onAction
|
||||
geometry.margin: 5
|
||||
overflow.y: scroll
|
||||
- id: paginator
|
||||
$type: ru.m.puzzlez.view.common.PaginatorView
|
||||
geometry.width: 100%
|
||||
+onPageSelect: |
|
||||
~(index) -> {
|
||||
page.index = index;
|
||||
refresh();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package ru.m.puzzlez.view;
|
||||
package ru.m.puzzlez.view.common;
|
||||
|
||||
import haxework.view.data.DataView;
|
||||
import haxework.view.form.ButtonView;
|
||||
Reference in New Issue
Block a user