~sirn/fanboi2

5b436e758084b9777685d5f69a4402a84f1de4c0 — Kridsada Thanabulpong 4 months ago 857635e
templates: display ident_v6 as ID6
M assets/app/javascripts/models/post.ts => assets/app/javascripts/models/post.ts +10 -6
@@ 11,6 11,7 @@ export class Post extends Model {
    bumped: boolean;
    createdAt: string;
    ident: string;
    identType: string;
    name: string;
    number: number;
    topicId: number;


@@ 26,6 27,7 @@ export class Post extends Model {
        this.bumped = data["bumped"];
        this.createdAt = data["created_at"];
        this.ident = data["ident"];
        this.identType = data["ident_type"];
        this.name = data["name"];
        this.number = data["number"];
        this.topicId = data["topic_id"];


@@ 35,7 37,7 @@ export class Post extends Model {
    static queryAll(
        topicId: number,
        query?: string,
        token?: CancellableToken,
        token?: CancellableToken
    ): Promise<Post[]> {
        let entryPoint = `/api/1.0/topics/${topicId}/posts/`;



@@ 44,16 46,18 @@ export class Post extends Model {
        }

        return request("GET", entryPoint, {}, token).then(resp => {
            return JSON.parse(resp).map((data: Object): Post => {
                return new Post(data);
            });
            return JSON.parse(resp).map(
                (data: Object): Post => {
                    return new Post(data);
                }
            );
        });
    }

    static createOne(
        topicId: number,
        params: IRequestBody,
        token?: CancellableToken,
        token?: CancellableToken
    ): Promise<Post> {
        return request("POST", `/api/1.0/topics/${topicId}/posts/`, params, token).then(
            (resp: string) => {


@@ 66,7 70,7 @@ export class Post extends Model {
                } else {
                    return new Post(data);
                }
            },
            }
        );
    }
}

M assets/app/javascripts/views/post_collection_view.ts => assets/app/javascripts/views/post_collection_view.ts +41 -20
@@ 17,14 17,16 @@ export class PostCollectionView {
        return h(
            "div",
            { className: "js-post-collection" },
            posts.map((post: Post): VNode => {
                return h("div", { className: "post" }, [
                    h("div", { className: "container" }, [
                        PostCollectionView.renderHeader(post),
                        PostCollectionView.renderBody(post),
                    ]),
                ]);
            }),
            posts.map(
                (post: Post): VNode => {
                    return h("div", { className: "post" }, [
                        h("div", { className: "container" }, [
                            PostCollectionView.renderHeader(post),
                            PostCollectionView.renderBody(post)
                        ])
                    ]);
                }
            )
        );
    }



@@ 33,7 35,7 @@ export class PostCollectionView {
            PostCollectionView.renderHeaderNumber(post),
            PostCollectionView.renderHeaderName(post),
            PostCollectionView.renderHeaderDate(post),
            PostCollectionView.renderHeaderIdent(post),
            PostCollectionView.renderHeaderIdent(post)
        ]);
    }



@@ 49,10 51,10 @@ export class PostCollectionView {
            {
                className: classList.join(" "),
                dataset: {
                    topicQuickReply: post.number,
                },
                    topicQuickReply: post.number
                }
            },
            [post.number.toString()],
            [post.number.toString()]
        );
    }



@@ 60,9 62,9 @@ export class PostCollectionView {
        return h(
            "span",
            {
                className: "post-header-item name",
                className: "post-header-item name"
            },
            [post.name],
            [post.name]
        );
    }



@@ 73,20 75,39 @@ export class PostCollectionView {
        return h(
            "span",
            {
                className: "post-header-item date",
                className: "post-header-item date"
            },
            [`Posted ${formatter}`],
            [`Posted ${formatter}`]
        );
    }

    private static renderHeaderIdent(post: Post): VNode | string {
        if (post.ident) {
            let identCls = ["post-header-item", "ident"];
            let identName = "ID";

            switch (post.identType) {
                case "ident_v6": {
                    identName = "ID6";
                    identCls.push("ident-v6");
                    break;
                }

                default: {
                    identName = "ID";
                    if (post.identType != "ident") {
                        identCls.push(post.identType.replace("_", "-"));
                    }
                    break;
                }
            }

            return h(
                "span",
                {
                    className: "post-header-item ident",
                    className: identCls.join(" ")
                },
                [`ID:${post.ident}`],
                [`${identName}:${post.ident}`]
            );
        } else {
            return "";


@@ 98,9 119,9 @@ export class PostCollectionView {
            "div",
            {
                className: "post-body",
                innerHTML: post.bodyFormatted,
                innerHTML: post.bodyFormatted
            },
            [],
            []
        );
    }
}

M fanboi2/templates/partials/_ident.mako => fanboi2/templates/partials/_ident.mako +2 -2
@@ 1,5 1,5 @@
<%def name="render_ident(ident, ident_type='ident', class_=None)">
    % if ident:
    <span class="${class_ + ' ' if class_ else ''}ident${' ' + ident_type.replace('_', '-') if ident_type != 'ident' else ''}">ID:${ident}</span>
    <span class="${class_ + ' ' if class_ else ''}ident${' ' + ident_type.replace('_', '-') if ident_type != 'ident' else ''}">${'ID6' if ident_type == 'ident_v6' else 'ID'}:${ident}</span>
    % endif
</%def>
\ No newline at end of file
</%def>