feat: composite objects in excel extra
# Conflicts: # frontend/src/App.vue
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export * from "./models.js";
|
||||
@@ -1,190 +0,0 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import {Create as $Create} from "@wailsio/runtime";
|
||||
|
||||
export class Author {
|
||||
"Id": number;
|
||||
"Name": string;
|
||||
"Posts": Post[];
|
||||
"Comments": Comment[];
|
||||
|
||||
/** Creates a new Author instance. */
|
||||
constructor($$source: Partial<Author> = {}) {
|
||||
if (!("Id" in $$source)) {
|
||||
this["Id"] = 0;
|
||||
}
|
||||
if (!("Name" in $$source)) {
|
||||
this["Name"] = "";
|
||||
}
|
||||
if (!("Posts" in $$source)) {
|
||||
this["Posts"] = [];
|
||||
}
|
||||
if (!("Comments" in $$source)) {
|
||||
this["Comments"] = [];
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Author instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): Author {
|
||||
const $$createField2_0 = $$createType1;
|
||||
const $$createField3_0 = $$createType3;
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
if ("Posts" in $$parsedSource) {
|
||||
$$parsedSource["Posts"] = $$createField2_0($$parsedSource["Posts"]);
|
||||
}
|
||||
if ("Comments" in $$parsedSource) {
|
||||
$$parsedSource["Comments"] = $$createField3_0($$parsedSource["Comments"]);
|
||||
}
|
||||
return new Author($$parsedSource as Partial<Author>);
|
||||
}
|
||||
}
|
||||
|
||||
export class Comment {
|
||||
"Id": number;
|
||||
"Text": string;
|
||||
"AuthorId": number;
|
||||
"Author": Author;
|
||||
"Posts": Post[];
|
||||
|
||||
/** Creates a new Comment instance. */
|
||||
constructor($$source: Partial<Comment> = {}) {
|
||||
if (!("Id" in $$source)) {
|
||||
this["Id"] = 0;
|
||||
}
|
||||
if (!("Text" in $$source)) {
|
||||
this["Text"] = "";
|
||||
}
|
||||
if (!("AuthorId" in $$source)) {
|
||||
this["AuthorId"] = 0;
|
||||
}
|
||||
if (!("Author" in $$source)) {
|
||||
this["Author"] = (new Author());
|
||||
}
|
||||
if (!("Posts" in $$source)) {
|
||||
this["Posts"] = [];
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Comment instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): Comment {
|
||||
const $$createField3_0 = $$createType4;
|
||||
const $$createField4_0 = $$createType1;
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
if ("Author" in $$parsedSource) {
|
||||
$$parsedSource["Author"] = $$createField3_0($$parsedSource["Author"]);
|
||||
}
|
||||
if ("Posts" in $$parsedSource) {
|
||||
$$parsedSource["Posts"] = $$createField4_0($$parsedSource["Posts"]);
|
||||
}
|
||||
return new Comment($$parsedSource as Partial<Comment>);
|
||||
}
|
||||
}
|
||||
|
||||
export class Post {
|
||||
"Id": number;
|
||||
"Text": string;
|
||||
"Deadline": number;
|
||||
"CreatedAt": number;
|
||||
"AuthorId": number;
|
||||
"Author": Author;
|
||||
"PostTypeId": number;
|
||||
"PostType": PostType;
|
||||
"Comments": Comment[];
|
||||
|
||||
/** Creates a new Post instance. */
|
||||
constructor($$source: Partial<Post> = {}) {
|
||||
if (!("Id" in $$source)) {
|
||||
this["Id"] = 0;
|
||||
}
|
||||
if (!("Text" in $$source)) {
|
||||
this["Text"] = "";
|
||||
}
|
||||
if (!("Deadline" in $$source)) {
|
||||
this["Deadline"] = 0;
|
||||
}
|
||||
if (!("CreatedAt" in $$source)) {
|
||||
this["CreatedAt"] = 0;
|
||||
}
|
||||
if (!("AuthorId" in $$source)) {
|
||||
this["AuthorId"] = 0;
|
||||
}
|
||||
if (!("Author" in $$source)) {
|
||||
this["Author"] = (new Author());
|
||||
}
|
||||
if (!("PostTypeId" in $$source)) {
|
||||
this["PostTypeId"] = 0;
|
||||
}
|
||||
if (!("PostType" in $$source)) {
|
||||
this["PostType"] = (new PostType());
|
||||
}
|
||||
if (!("Comments" in $$source)) {
|
||||
this["Comments"] = [];
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Post instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): Post {
|
||||
const $$createField5_0 = $$createType4;
|
||||
const $$createField7_0 = $$createType5;
|
||||
const $$createField8_0 = $$createType3;
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
if ("Author" in $$parsedSource) {
|
||||
$$parsedSource["Author"] = $$createField5_0($$parsedSource["Author"]);
|
||||
}
|
||||
if ("PostType" in $$parsedSource) {
|
||||
$$parsedSource["PostType"] = $$createField7_0($$parsedSource["PostType"]);
|
||||
}
|
||||
if ("Comments" in $$parsedSource) {
|
||||
$$parsedSource["Comments"] = $$createField8_0($$parsedSource["Comments"]);
|
||||
}
|
||||
return new Post($$parsedSource as Partial<Post>);
|
||||
}
|
||||
}
|
||||
|
||||
export class PostType {
|
||||
"Id": number;
|
||||
"Name": string;
|
||||
|
||||
/** Creates a new PostType instance. */
|
||||
constructor($$source: Partial<PostType> = {}) {
|
||||
if (!("Id" in $$source)) {
|
||||
this["Id"] = 0;
|
||||
}
|
||||
if (!("Name" in $$source)) {
|
||||
this["Name"] = "";
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PostType instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): PostType {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new PostType($$parsedSource as Partial<PostType>);
|
||||
}
|
||||
}
|
||||
|
||||
// Private type creation functions
|
||||
const $$createType0 = Post.createFrom;
|
||||
const $$createType1 = $Create.Array($$createType0);
|
||||
const $$createType2 = Comment.createFrom;
|
||||
const $$createType3 = $Create.Array($$createType2);
|
||||
const $$createType4 = Author.createFrom;
|
||||
const $$createType5 = PostType.createFrom;
|
||||
@@ -1,65 +0,0 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import {Call as $Call, Create as $Create} from "@wailsio/runtime";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as models$0 from "../models/models.js";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as $models from "./models.js";
|
||||
|
||||
export function Count(): Promise<number> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3969879864) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
export function Create(item: $models.Author): Promise<$models.Author> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3684602449, item) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType0($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
export function Delete(id: number): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2096845974, id) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
export function GetAll(): Promise<($models.Author | null)[]> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3248293926) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType2($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
export function GetById(id: number): Promise<$models.Author | null> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(1703016211, id) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType1($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
export function Update(item: $models.Author): Promise<$models.Author> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2240704960, item) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType0($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
// Private type creation functions
|
||||
const $$createType0 = models$0.Author.createFrom;
|
||||
const $$createType1 = $Create.Nullable($$createType0);
|
||||
const $$createType2 = $Create.Array($$createType1);
|
||||
@@ -1,65 +0,0 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import {Call as $Call, Create as $Create} from "@wailsio/runtime";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as models$0 from "../models/models.js";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as $models from "./models.js";
|
||||
|
||||
export function Count(): Promise<number> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3225397984) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
export function Create(item: $models.Comment): Promise<$models.Comment> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(4239106089, item) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType0($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
export function Delete(id: number): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2553503582, id) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
export function GetAll(): Promise<($models.Comment | null)[]> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(1805763390) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType2($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
export function GetById(id: number): Promise<$models.Comment | null> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3217823099, id) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType1($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
export function Update(item: $models.Comment): Promise<$models.Comment> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3080970936, item) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType0($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
// Private type creation functions
|
||||
const $$createType0 = models$0.Comment.createFrom;
|
||||
const $$createType1 = $Create.Nullable($$createType0);
|
||||
const $$createType2 = $Create.Array($$createType1);
|
||||
@@ -1,15 +0,0 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
import * as AuthorService from "./authorservice.js";
|
||||
import * as CommentService from "./commentservice.js";
|
||||
import * as PostService from "./postservice.js";
|
||||
import * as PostTypeService from "./posttypeservice.js";
|
||||
export {
|
||||
AuthorService,
|
||||
CommentService,
|
||||
PostService,
|
||||
PostTypeService
|
||||
};
|
||||
|
||||
export * from "./models.js";
|
||||
@@ -1,22 +0,0 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import {Create as $Create} from "@wailsio/runtime";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as models$0 from "../models/models.js";
|
||||
|
||||
export const Author = models$0.Author;
|
||||
export type Author = models$0.Author;
|
||||
|
||||
export const Comment = models$0.Comment;
|
||||
export type Comment = models$0.Comment;
|
||||
|
||||
export const Post = models$0.Post;
|
||||
export type Post = models$0.Post;
|
||||
|
||||
export const PostType = models$0.PostType;
|
||||
export type PostType = models$0.PostType;
|
||||
@@ -1,70 +0,0 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import {Call as $Call, Create as $Create} from "@wailsio/runtime";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as models$0 from "../models/models.js";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as $models from "./models.js";
|
||||
|
||||
export function Count(): Promise<number> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3109924027) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
export function Create(item: $models.Post): Promise<$models.Post> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(1443399856, item) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType0($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
export function Delete(id: number): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2924549135, id) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
export function ExportToExcel(): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(75322242) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
export function GetAll(): Promise<($models.Post | null)[]> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(65691059) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType2($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
export function GetById(id: number): Promise<$models.Post | null> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(4074736792, id) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType1($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
export function Update(item: $models.Post): Promise<$models.Post> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(137798821, item) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType0($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
// Private type creation functions
|
||||
const $$createType0 = models$0.Post.createFrom;
|
||||
const $$createType1 = $Create.Nullable($$createType0);
|
||||
const $$createType2 = $Create.Array($$createType1);
|
||||
@@ -1,70 +0,0 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import {Call as $Call, Create as $Create} from "@wailsio/runtime";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as models$0 from "../models/models.js";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as $models from "./models.js";
|
||||
|
||||
export function Count(): Promise<number> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(554487955) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
export function Create(item: $models.PostType): Promise<$models.PostType> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(1092898136, item) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType0($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
export function Delete(id: number): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2114913543, id) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
export function GetAll(): Promise<($models.PostType | null)[]> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(416231387) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType2($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
export function GetById(id: number): Promise<$models.PostType | null> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3237123344, id) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType1($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
export function ImportFromExcel(): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(1671814244) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
export function Update(item: $models.PostType): Promise<$models.PostType> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2773888269, item) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType0($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
// Private type creation functions
|
||||
const $$createType0 = models$0.PostType.createFrom;
|
||||
const $$createType1 = $Create.Nullable($$createType0);
|
||||
const $$createType2 = $Create.Array($$createType1);
|
||||
@@ -7,6 +7,8 @@ import type { Scheme } from "../types/scheme.type";
|
||||
import { PostType } from "../../bindings/app/internal/services";
|
||||
import { ref } from "vue";
|
||||
import type { Validate } from "../types/validate.type";
|
||||
import { ImportFromExcel } from "../../bindings/app/internal/services/posttypeservice.ts";
|
||||
import { ExportToExcel } from "../../bindings/app/internal/services/postservice.ts";
|
||||
|
||||
const service = new Service();
|
||||
|
||||
@@ -19,6 +21,7 @@ const load = async () => {
|
||||
|
||||
onMounted(async () => {
|
||||
await load();
|
||||
await ExportToExcel();
|
||||
});
|
||||
|
||||
const scheme: Scheme<PostType> = reactive({
|
||||
|
||||
@@ -86,7 +86,6 @@ func ExportEntityToSpreadsheet[T any](file *excelize.File, sheetName string, ent
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: process composite objects
|
||||
// TODO: appearance
|
||||
for i, item := range items {
|
||||
structValue := reflect.ValueOf(item).Elem()
|
||||
@@ -123,6 +122,24 @@ func ExportEntityToSpreadsheet[T any](file *excelize.File, sheetName string, ent
|
||||
|
||||
slog.Info(fmt.Sprintf("Field %s value: %v, %s\n", cellName, fieldValue, datatype))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
cellName, err := GetCellNameByIndices(j+columnOffset, i+1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
structInfo := structValue.Type().Field(j)
|
||||
structVal := structValue.Field(j)
|
||||
|
||||
value, err := SerializeNestedField(structInfo, structVal)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = file.SetCellValue(sheetName, cellName, *value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -133,6 +150,74 @@ func ExportEntityToSpreadsheet[T any](file *excelize.File, sheetName string, ent
|
||||
return nil
|
||||
}
|
||||
|
||||
func getNestedFieldValue(obj reflect.Value, path string) (any, error) {
|
||||
fields := strings.Split(path, ".")
|
||||
val := obj
|
||||
|
||||
for _, field := range fields {
|
||||
if field == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if val.Kind() == reflect.Ptr {
|
||||
val = val.Elem()
|
||||
}
|
||||
|
||||
val = val.FieldByName(field)
|
||||
|
||||
if !val.IsValid() {
|
||||
return nil, fmt.Errorf("field %s not found", field)
|
||||
}
|
||||
}
|
||||
return val.Interface(), nil
|
||||
}
|
||||
|
||||
func SerializeNestedField(fieldInfo reflect.StructField, fieldValue reflect.Value) (*string, error) {
|
||||
tag, err := fogg.Parse(string(fieldInfo.Tag))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var uiTag fogg.Tag
|
||||
|
||||
if tag.HasTag("ui") && tag.GetTag("ui").HasParam("field") {
|
||||
uiTag = *tag.GetTag("ui")
|
||||
} else {
|
||||
slog.Error("Fail to extract Field tag")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if uiTag.HasParam("field") {
|
||||
slog.Info("Found `field` tag")
|
||||
var result string
|
||||
fieldPath := uiTag.GetParam("field").Value
|
||||
if fieldInfo.Type.Kind() == reflect.Slice {
|
||||
slog.Info("Found `slice` tag")
|
||||
var items = make([]string, fieldValue.Len())
|
||||
for i := 0; i < fieldValue.Len(); i++ {
|
||||
item := fieldValue.Index(i)
|
||||
nestedFieldValue, err := getNestedFieldValue(item, fieldPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items[i] = fmt.Sprintf("%v", nestedFieldValue)
|
||||
}
|
||||
result = strings.Join(items, ", ")
|
||||
} else {
|
||||
nestedFieldValue, err := getNestedFieldValue(fieldValue, fieldPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result = fmt.Sprintf("%v", nestedFieldValue)
|
||||
}
|
||||
slog.Info(fmt.Sprintf("Field %s value: %v", fieldPath, result))
|
||||
return &result, nil
|
||||
} else {
|
||||
slog.Error("Field `field` tag not found")
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetHeaderCellNameByIndex(column int) (string, error) {
|
||||
colName, err := excelize.ColumnNumberToName(column + 1)
|
||||
if err != nil {
|
||||
@@ -172,11 +257,6 @@ func ExportHeaders(entity any) (TableHeaders, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
if !isPrimitiveType(v.Field(i).Type) {
|
||||
headers.IgnoredFieldsIndexes = append(headers.IgnoredFieldsIndexes, i)
|
||||
continue
|
||||
}
|
||||
|
||||
label := uiTag.GetParamOr("label", uiTag.GetParamOr(excelNameTag, ""))
|
||||
|
||||
if label != "" {
|
||||
@@ -288,6 +368,11 @@ func WriteData(file *excelize.File, filename string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if filepath == "" {
|
||||
dialogs.InfoDialog("Экспорт данных", "Операция отменена")
|
||||
}
|
||||
|
||||
if err := file.SaveAs(filepath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user