Skip to content

Commit

Permalink
Merge pull request #37 from GreenPix/fix-commit
Browse files Browse the repository at this point in the history
Fix map commit action + false login error
  • Loading branch information
Nemikolh authored Sep 10, 2016
2 parents f82e35f + 26e028e commit 5fe220c
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion editor/components/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class CommitModal {
this.hide();
}, err => {
this.committing = false;
this.error_message = `Couldn't commit, cause: '${err}'`;
this.error_message = `Couldn't commit, cause: '${err.json().message}'`;
console.log(err);
});
}
Expand Down
7 changes: 4 additions & 3 deletions editor/components/login/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export class LoginForm {
this.password
).subscribe(res => {
if (res.status === 200) {
this.username = '';
this.password = '';
this.router.navigate([this.auth.redirectUrl()]);
this.router.navigate([this.auth.redirectUrl()]).then(() => {
this.username = '';
this.password = '';
});
} else {
this.loginAttemptFailed = true;
}
Expand Down
1 change: 0 additions & 1 deletion editor/components/webgl/simple-surface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {init_gl_default} from './helpers';
selector: 'img-webgl-surface',
styles: [
`canvas { width: 100%; height: 100% }`,
`.display-none { display: none; }`
],
template:
`<canvas id="{{id}}" [ngClass] = "{'display-none': gl_not_supported }"></canvas>
Expand Down
1 change: 0 additions & 1 deletion editor/components/webgl/surface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface KeyHandler {
selector: 'webgl-surface',
styles: [
`canvas { width: 100%; height: 100% }`,
`.display-none { display: none; }`
],
template: `<canvas id="{{id}}" tabindex="1"
(keydown)="keyPressed($event)"
Expand Down
17 changes: 10 additions & 7 deletions editor/models/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export interface ChipsetLayer {
chipset: string;
}

function intoMongoDbId(chipset: ChipsetLayer): string {
return chipset.chipset.substr(chipset.chipset.lastIndexOf('/') + 1);
}

export class Layer {

constructor(
Expand Down Expand Up @@ -131,30 +135,29 @@ export class MapManager implements Committer {

commit(map: Map, comment: string): Observable<any> {
if (map.is_new) {
let observable = this.http.post(`/api/map/new`, {
return this.http.post(`/api/maps/new`, {
name: map.name,
layers: map.layers.map(l =>
l.raw.map(c => ({
tiles_id_base64: intoBase64(c.tiles_id),
chipset_id: c.chipset
chipset_id: intoMongoDbId(c)
}))
),
width: map.width,
height: map.height,
tile_size: map.tile_size,
comment,
} as MapData);
observable.subscribe(res => {
} as MapData)
.do(res => {
if (res.status === 200) {
map.is_new = false;
}
});
return observable;
}
return this.http.post(`/api/map/${map.name}/commit`, {
return this.http.post(`/api/maps/${map.name}/commit`, {
layers: map.layers.map(l => l.raw.map(c => ({
tiles_id_base64: intoBase64(c.tiles_id),
chipset_id: c.chipset
chipset_id: intoMongoDbId(c)
}))),
comment,
} as MapCommitData);
Expand Down
13 changes: 4 additions & 9 deletions editor/modules/map/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ <h4 class="lead text-center">Palette</h4>

</nav>

<alert-box></alert-box>

<div [ngSwitch]="state.stateStr()">
<template [ngSwitchCase]="'editor'">

<layer-panel [currentMap]="map_manager.currentMap()"
(selectLayer)="onSelectLayer($event)"></layer-panel>

</template>
<div>
<layer-panel [ngClass]="{ 'display-none': state.stateStr() !== 'editor' }"
[currentMap]="map_manager.currentMap()"
(selectLayer)="onSelectLayer($event)"></layer-panel>
</div>
4 changes: 3 additions & 1 deletion editor/modules/map/layers-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ export class LayersPanel implements OnChanges, AfterViewInit, OnDestroy {
}

private requestLayerPreviews() {
this.current_map.layers
if (this.current_map) {
this.current_map.layers
.forEach((_, i) => this.area.layer_index_stream.next(i));
}
}
}
2 changes: 2 additions & 0 deletions editor/rxjs-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/share';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/delay';
import 'rxjs/add/observable/of';
import 'rxjs/add/observable/fromEvent';
2 changes: 2 additions & 0 deletions editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ header.navbar.navbar-fixed-top.navbar-empty {
top: $navbar-height + 12px;
height: 56px; // Same for this value
}

.display-none { display: none; }
12 changes: 6 additions & 6 deletions server/apis/chipsets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ app.post('/api/chipset/upload/', reqAuth, upload.single('chipset'),

app.get('/api/chipset/', reqAuth, (req, res) => {
ChipsetModel.find({})
.select('name')
.select('id')
.exec((err, chipsets) => {
if (err) {
werr(err);
serverError(res, `Couldn't get the list of chipsets.`);
} else {
res.status(200).json(chipsets.map(c => c.name));
res.status(200).json(chipsets.map(c => c.id));
}
});
});

app.get('/api/chipset/:name/metadata', reqAuth, (req, res) => {
ChipsetModel.findOne({ name: req.params.name }, (err, chipset) => {
app.get('/api/chipset/:id/metadata', reqAuth, (req, res) => {
ChipsetModel.findById(req.params.id, (err, chipset) => {
if (err || !chipset) {
if (err) werr(err);
notFound(res, req.user);
Expand All @@ -60,8 +60,8 @@ app.get('/api/chipset/:name/metadata', reqAuth, (req, res) => {
});
});

app.get('/api/chipset/:name', reqAuth, (req, res) => {
ChipsetModel.findOne({ name: req.params.name }, (err, chipset) => {
app.get('/api/chipset/:id', reqAuth, (req, res) => {
ChipsetModel.findById(req.params.id, (err, chipset) => {
if (err || !chipset) {
if (err) werr(err);
notFound(res, req.user);
Expand Down
3 changes: 1 addition & 2 deletions server/validators/api_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const layerDataSchema = {
minItems: 1,
items: {
type: 'array',
minItems: 1,
items: {
required: true,
type: 'object',
Expand Down Expand Up @@ -54,7 +53,7 @@ export const validateMapNew = validator({
},
comment: {
required: true,
type: 'number'
type: 'string'
}
}
}, {
Expand Down

0 comments on commit 5fe220c

Please sign in to comment.