Skip to content

Instantly share code, notes, and snippets.

View kutliev's full-sized avatar

Bulat Kutliev kutliev

View GitHub Profile
@kutliev
kutliev / entity.ts
Created February 11, 2018 07:03
Entity class
export class Entity {
id: string;
title: string;
slug: string;
content: string;
constructor(id: string, title: string, slug: string, content: string) {
this.id = id;
this.title = title;
@kutliev
kutliev / spot.ts
Created February 11, 2018 18:51
spot class
import { Entity } from './entity'
import { SpotEvent } from './spotevent'
export class Spot extends Entity {
floor: string;
type: string;
customer: string;
payments: SpotEvent[];
@kutliev
kutliev / settings.ts
Created February 11, 2018 18:53
Settings class
import { environment } from '../../environments/environment'
export class Settings {
ApiEndPoint: string = environment.COSMIC_API + environment.COSMIC_BUCKET + "/";
ApiReadKey: string = environment.COSMIC_READ_KEY;
ApiWriteKey: string = environment.COSMIC_WRITE_KEY;
}
export const SpotTypes = ['Vacant', 'Rent', 'Owned'];
export const EventTypes = ['Payment', 'Maintenance', 'Cleaning'];
@kutliev
kutliev / app-routing.module.ts
Last active February 11, 2018 19:08
Routing
const appRoutes = [
{ path: '', component: DashboardComponent },
{ path: 'spots', component: SpotcardComponent },
{ path: 'spots/:spot_slug', component: SpotcardComponent },
{ path: 'spots/:spot_slug/edit', component: SpotcardeditComponent },
{ path: 'spots/:spot_slug/addevent', component: EventcardeditComponent },
{ path: 'spots/:spot_slug/events/', redirectTo: 'spots/:spot_slug' },
{ path: 'spots/:spot_slug/events/:event_slug', component: EventcardeditComponent },
{ path: 'createspot', component: SpotcardeditComponent },
// otherwise redirect to home
@kutliev
kutliev / app.component.html
Created February 11, 2018 19:16
Router-outlet
<section class="section">
<div class="container">
<router-outlet></router-outlet>
</div>
</section>
@kutliev
kutliev / data.service.ts
Created February 11, 2018 19:34
Data service
getSpotData(): Observable<any> {
let apiEndPoint = this.settings.ApiEndPoint + "object-type/spots" + "?read_key=" + this.settings.ApiReadKey;
return this.http.get(apiEndPoint).map((response: Response) => response.json().objects);
}
getSpotEvents(): Observable<any> {
let apiEndPoint = this.settings.ApiEndPoint + "object-type/spotevents" + "?read_key=" + this.settings.ApiReadKey;
return this.http.get(apiEndPoint).map((response: Response) => response.json().objects);
}
@kutliev
kutliev / spotlist.component.html
Last active February 11, 2018 19:37
Spot list
<tbody>
<tr *ngFor="let spot of spots">
<td class="has-text-grey">{{ spot.floor }}</td>
<td><a routerLink="/spots/{{ spot.slug }}">{{ spot.title }}</a></td>
<td>{{ spot.type }}</td>
<td class="has-text-right">{{ spot.payments.length }}</td>
<td class="has-text-right">{{ spot.maintenances.length }}</td>
<td class="has-text-right">{{ spot.cleanings.length }}</td>
<td>
<a class="button is-primary is-small" routerLink="/spots/{{ spot.slug }}/addevent" title="Add event">
@kutliev
kutliev / spotcard.component.html
Created February 11, 2018 19:39
Angular button
<button class="button is-danger" *ngIf="canBeDeleted(); else deleteWarning" (click)="remove(selectedSpot)">Delete</button>
@kutliev
kutliev / data.service.ts
Created February 11, 2018 19:40
Spot save
saveSpot(spot: Spot): Observable<any> {
let apiEndPoint = this.settings.ApiEndPoint + "add-object";
let payload = {
"write_key": this.settings.ApiWriteKey,
"title": spot.title,
"type_slug": "spots",
"content": spot.content,
"metafields": [
{
"key": "type",
@kutliev
kutliev / data.service.ts
Created February 11, 2018 19:42
Removing entity
removeSpot(spot: Spot) {
return this.removeEntity(spot).map((response: Response) => response.json());
}
removeEvent(event: SpotEvent) {
return this.removeEntity(event).map((response: Response) => response.json());
}
removeEntity(entity: Entity) {
let apiEndPoint = this.settings.ApiEndPoint + "objects/" + entity.slug;