2023-02-14 09:20:15 -05:00
|
|
|
import { drawHeader } from "wizard/lib/preview";
|
2019-11-07 16:38:28 -05:00
|
|
|
import { observes } from "discourse-common/utils/decorators";
|
2023-02-14 09:20:15 -05:00
|
|
|
import WizardPreviewBaseComponent from "./wizard-preview-base";
|
2016-09-16 16:12:56 -04:00
|
|
|
|
2023-02-14 09:20:15 -05:00
|
|
|
export default WizardPreviewBaseComponent.extend({
|
|
|
|
width: 400,
|
|
|
|
height: 100,
|
2016-09-16 16:12:56 -04:00
|
|
|
image: null,
|
|
|
|
|
|
|
|
@observes("field.value")
|
|
|
|
imageChanged() {
|
|
|
|
this.reload();
|
|
|
|
},
|
|
|
|
|
2016-09-21 16:09:18 -04:00
|
|
|
images() {
|
|
|
|
return { image: this.get("field.value") };
|
2016-09-16 16:12:56 -04:00
|
|
|
},
|
|
|
|
|
2020-10-05 13:40:41 -04:00
|
|
|
paint({ ctx, colors, font, width, height }) {
|
2016-09-16 16:12:56 -04:00
|
|
|
const headerHeight = height / 2;
|
|
|
|
|
|
|
|
drawHeader(ctx, colors, width, headerHeight);
|
|
|
|
|
|
|
|
const image = this.image;
|
2020-10-05 13:40:41 -04:00
|
|
|
|
2016-09-16 16:12:56 -04:00
|
|
|
const headerMargin = headerHeight * 0.2;
|
|
|
|
|
|
|
|
const imageHeight = headerHeight - headerMargin * 2;
|
|
|
|
const ratio = imageHeight / image.height;
|
2016-09-21 16:48:48 -04:00
|
|
|
this.scaleImage(
|
|
|
|
image,
|
|
|
|
headerMargin,
|
|
|
|
headerMargin,
|
|
|
|
image.width * ratio,
|
|
|
|
imageHeight
|
|
|
|
);
|
2016-09-16 16:12:56 -04:00
|
|
|
|
2020-08-31 06:14:09 -04:00
|
|
|
this.drawPills(colors, font, height / 2);
|
2016-09-16 16:12:56 -04:00
|
|
|
},
|
|
|
|
});
|