discourse/app/assets/javascripts/wizard/addon/components/image-preview-logo.js
Godfrey Chan 2228f75645
DEV: Modernize Wizard model implementation (#23640)
+ native classes
+ tracked properties
- Ember.Object
- Ember.Evented
- observers
- mixins
- computed/discourseComputed

Also removes unused wizard infrastructure for warnings. It appears
that once upon on time, either the server can generate warnings,
or some client code can generate them, which requires an extra 
confirmation from the user before they can continue to the next step.

This code is not tested and appears unused and defunct. Nothing
generates such warning and the server does not serialize them.

Extracted from https://github.com/discourse/discourse/pull/23678
2023-11-23 16:35:51 +00:00

51 lines
1.1 KiB
JavaScript

import { action } from "@ember/object";
import { drawHeader } from "wizard/lib/preview";
import WizardPreviewBaseComponent from "./wizard-preview-base";
export default WizardPreviewBaseComponent.extend({
width: 400,
height: 100,
image: null,
didInsertElement() {
this._super(...arguments);
this.field.addListener(this.imageChanged);
},
willDestroyElement() {
this._super(...arguments);
this.field.removeListener(this.imageChanged);
},
@action
imageChanged() {
this.reload();
},
images() {
return { image: this.field.value };
},
paint({ ctx, colors, font, width, height }) {
const headerHeight = height / 2;
drawHeader(ctx, colors, width, headerHeight);
const image = this.image;
const headerMargin = headerHeight * 0.2;
const imageHeight = headerHeight - headerMargin * 2;
const ratio = imageHeight / image.height;
this.scaleImage(
image,
headerMargin,
headerMargin,
image.width * ratio,
imageHeight
);
this.drawPills(colors, font, height / 2);
},
});