typing improvements
This commit is contained in:
		
							parent
							
								
									7fc0d82354
								
							
						
					
					
						commit
						b99a6ccc68
					
				
					 4 changed files with 32 additions and 21 deletions
				
			
		| 
						 | 
					@ -46,7 +46,7 @@
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
import { Dictionary } from "@/lib/api";
 | 
					import { NumStrDict, objForEach } from "@/lib/api";
 | 
				
			||||||
import { Options, Vue } from "vue-class-component";
 | 
					import { Options, Vue } from "vue-class-component";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import MultiModal from "../MultiModal.vue";
 | 
					import MultiModal from "../MultiModal.vue";
 | 
				
			||||||
| 
						 | 
					@ -62,7 +62,7 @@ import BulmaDrawer from "../bulma/Drawer.vue";
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
export default class extends Vue {
 | 
					export default class extends Vue {
 | 
				
			||||||
  public day_data: {
 | 
					  public day_data: {
 | 
				
			||||||
    [day: string]: {
 | 
					    [day: number]: {
 | 
				
			||||||
      part: string;
 | 
					      part: string;
 | 
				
			||||||
      image_name: string;
 | 
					      image_name: string;
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
| 
						 | 
					@ -76,32 +76,32 @@ export default class extends Vue {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public on_open(ready: () => void, fail: () => void): void {
 | 
					  public on_open(ready: () => void, fail: () => void): void {
 | 
				
			||||||
    Promise.all([
 | 
					    Promise.all([
 | 
				
			||||||
      this.$advent22.api_get<Dictionary>("admin/day_parts"),
 | 
					      this.$advent22.api_get<NumStrDict>("admin/day_parts"),
 | 
				
			||||||
      this.$advent22.api_get<Dictionary>("admin/day_image_names"),
 | 
					      this.$advent22.api_get<NumStrDict>("admin/day_image_names"),
 | 
				
			||||||
    ])
 | 
					    ])
 | 
				
			||||||
      .then(([day_parts, day_image_names]) => {
 | 
					      .then(([day_parts, day_image_names]) => {
 | 
				
			||||||
        const _ensure_day = (day: string) => {
 | 
					        const _ensure_day_in_data = (day: number) => {
 | 
				
			||||||
          if (!(day in this.day_data)) {
 | 
					          if (!(day in this.day_data)) {
 | 
				
			||||||
            this.day_data[day] = { part: "", image_name: "" };
 | 
					            this.day_data[day] = { part: "", image_name: "" };
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const day in day_parts) {
 | 
					        objForEach(day_parts, (day, part) => {
 | 
				
			||||||
          _ensure_day(day);
 | 
					          _ensure_day_in_data(day);
 | 
				
			||||||
          this.day_data[day].part = day_parts[day];
 | 
					          this.day_data[day].part = part;
 | 
				
			||||||
        }
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const day in day_image_names) {
 | 
					        objForEach(day_image_names, (day, image_name) => {
 | 
				
			||||||
          _ensure_day(day);
 | 
					          _ensure_day_in_data(day);
 | 
				
			||||||
          this.day_data[day].image_name = day_image_names[day];
 | 
					          this.day_data[day].image_name = image_name;
 | 
				
			||||||
        }
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ready();
 | 
					        ready();
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
      .catch(fail);
 | 
					      .catch(fail);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public door_click(day: unknown) {
 | 
					  public door_click(day: number) {
 | 
				
			||||||
    if (this.multi_modal === undefined) return;
 | 
					    if (this.multi_modal === undefined) return;
 | 
				
			||||||
    this.multi_modal.show_progress();
 | 
					    this.multi_modal.show_progress();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -122,7 +122,7 @@
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
import { ConfigModel, Dictionary, DoorsSaved } from "@/lib/api";
 | 
					import { ConfigModel, DoorsSaved, NumStrDict } from "@/lib/api";
 | 
				
			||||||
import { DateTime } from "luxon";
 | 
					import { DateTime } from "luxon";
 | 
				
			||||||
import { Options, Vue } from "vue-class-component";
 | 
					import { Options, Vue } from "vue-class-component";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -167,7 +167,7 @@ export default class extends Vue {
 | 
				
			||||||
      config_file: "sed diam nonumy",
 | 
					      config_file: "sed diam nonumy",
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  public day_parts: Dictionary = {};
 | 
					  public day_parts: NumStrDict = {};
 | 
				
			||||||
  public num_user_doors = 0;
 | 
					  public num_user_doors = 0;
 | 
				
			||||||
  public next_door: number | null = null;
 | 
					  public next_door: number | null = null;
 | 
				
			||||||
  public dav_credentials: Credentials = { username: "", password: "" };
 | 
					  public dav_credentials: Credentials = { username: "", password: "" };
 | 
				
			||||||
| 
						 | 
					@ -183,7 +183,7 @@ export default class extends Vue {
 | 
				
			||||||
  public on_open(ready: () => void, fail: () => void): void {
 | 
					  public on_open(ready: () => void, fail: () => void): void {
 | 
				
			||||||
    Promise.all([
 | 
					    Promise.all([
 | 
				
			||||||
      this.$advent22.api_get<ConfigModel>("admin/config_model"),
 | 
					      this.$advent22.api_get<ConfigModel>("admin/config_model"),
 | 
				
			||||||
      this.$advent22.api_get<Dictionary>("admin/day_parts"),
 | 
					      this.$advent22.api_get<NumStrDict>("admin/day_parts"),
 | 
				
			||||||
      this.$advent22.api_get<DoorsSaved>("user/doors"),
 | 
					      this.$advent22.api_get<DoorsSaved>("user/doors"),
 | 
				
			||||||
      this.$advent22.api_get<number | null>("user/next_door"),
 | 
					      this.$advent22.api_get<number | null>("user/next_door"),
 | 
				
			||||||
    ])
 | 
					    ])
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,8 +23,8 @@ export interface ConfigModel {
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface Dictionary {
 | 
					export interface NumStrDict {
 | 
				
			||||||
  [day: string]: string;
 | 
					  [key: number]: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface DoorSaved {
 | 
					export interface DoorSaved {
 | 
				
			||||||
| 
						 | 
					@ -36,3 +36,14 @@ export interface DoorSaved {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type DoorsSaved = DoorSaved[];
 | 
					export type DoorsSaved = DoorSaved[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function objForEach<T>(
 | 
				
			||||||
 | 
					  obj: T,
 | 
				
			||||||
 | 
					  f: (k: keyof T, v: T[keyof T]) => void,
 | 
				
			||||||
 | 
					): void {
 | 
				
			||||||
 | 
					  for (const k in obj) {
 | 
				
			||||||
 | 
					    if (Object.prototype.hasOwnProperty.call(obj, k)) {
 | 
				
			||||||
 | 
					      f(k, obj[k]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,11 +24,11 @@ export class Advent22 {
 | 
				
			||||||
    return `//${window.location.hostname}:8000/api`;
 | 
					    return `//${window.location.hostname}:8000/api`;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public name_door(day: unknown): string {
 | 
					  public name_door(day: number): string {
 | 
				
			||||||
    return `Türchen ${day}`;
 | 
					    return `Türchen ${day}`;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public format_user_error([reason, endpoint]: unknown[]): string {
 | 
					  public format_user_error([reason, endpoint]: [unknown, string]): string {
 | 
				
			||||||
    let msg =
 | 
					    let msg =
 | 
				
			||||||
      "Unbekannter Fehler, bitte wiederholen! Besteht das Problem länger, bitte Admin benachrichtigen!";
 | 
					      "Unbekannter Fehler, bitte wiederholen! Besteht das Problem länger, bitte Admin benachrichtigen!";
 | 
				
			||||||
    let code = "U";
 | 
					    let code = "U";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue