Commit 1c5944bd authored by Girija Saint-Ange's avatar Girija Saint-Ange
Browse files

Merge branch '19-presets-from-kicker-extras-json-not-displayed-in-variable-dropdown' into 'master'

Resolve "Presets from kicker-extras.json Not Displayed in Variable Dropdown"

Closes #19

See merge request to-be-continuous/kicker!470
parents 810d2c57 afc7f515
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import { OptionsFormComponent } from '../options-form/options-form.component';
export class KickerComponent implements OnInit {

  private readonly http = inject(HttpClient);
  private readonly _templatesCache = new Map<string, Template[]>();
  
  aggregated: Aggregated;
  templates: Template[] = [];
@@ -30,6 +31,8 @@ export class KickerComponent implements OnInit {
      .subscribe(value => {
        this.aggregated = Aggregated.fromJson(value);
        this.templates = this.aggregated.templates;
        // Clear cache when templates are loaded
        this._templatesCache.clear();
        console.log(`templates loaded from ${environment.kickermodel.url}:`, this.aggregated);
      });
  }
@@ -40,14 +43,27 @@ export class KickerComponent implements OnInit {
   * @param addNone whether to add a 'none' template entry
   */
  templatesOfKind(kind: string, addNone?: boolean): Template[] {
    const cacheKey = `${kind}-${addNone || false}`;
    
    if (!this._templatesCache.has(cacheKey)) {
      const templates = this.templates.filter(t => t.kind === kind && this.options.hasExtension(t.extension_id));
      if (addNone) {
        templates.splice(0, 0, new Template('none', 'none...', 'No template selected.'));
      }
    return templates;
      this._templatesCache.set(cacheKey, templates);
    }
    
    return this._templatesCache.get(cacheKey) ?? [];
  }

  templatesNotOfKind(kinds: string[]): Template[] {
    return this.templates.filter(t => kinds.indexOf(t.kind) < 0 && this.options.hasExtension(t.extension_id));
    const cacheKey = `not-${kinds.join(',')}`;
    
    if (!this._templatesCache.has(cacheKey)) {
      const templates = this.templates.filter(t => !kinds.includes(t.kind) && this.options.hasExtension(t.extension_id));
      this._templatesCache.set(cacheKey, templates);
    }
    
    return this._templatesCache.get(cacheKey) ?? [];
  }
}
+3 −4
Original line number Diff line number Diff line
@@ -5,12 +5,11 @@
       <div class="col-md-9">
              <div [ngClass]="{'input-group-sm input-group': isText || isSelect, 'form-check': isCheckbox}">
                     <div *ngIf="hasPresets" ngbDropdown class="d-inline-block">
                            <button ngbDropdownToggle class="btn btn-outline-secondary" type="button"
                                   aria-haspopup="true" aria-expanded="false" title="Select a preset value">
                            <button ngbDropdownToggle class="btn btn-outline-secondary" type="button" title="Select a preset value">
                                   <span class="fas fa-lightbulb"></span>
                            </button>
                            <div ngbDropdownMenu class="dropdown-menu">
                                   <button *ngFor="let preset of presets" ngbDropdownItem href="javascript:null" (click)="aggregated.applyPreset(preset)"
                            <div ngbDropdownMenu>
                                   <button *ngFor="let preset of presets" ngbDropdownItem type="button" (click)="aggregated.applyPreset(preset)"
                                          [title]="preset.description">{{ preset.name }}</button>
                            </div>
                     </div>
+3 −2
Original line number Diff line number Diff line
@@ -2,12 +2,13 @@ import {Component, Input} from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { MarkdownModule } from 'ngx-markdown';
import { NgbDropdownModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
import {Aggregated, Options, Preset, Variable, VarType} from '../kicker';

@Component({
  selector: 'app-variable-editor',
  standalone: true,
  imports: [CommonModule, FormsModule, MarkdownModule],
  imports: [CommonModule, FormsModule, MarkdownModule, NgbDropdownModule, NgbTooltipModule],
  templateUrl: './variable-editor.component.html',
  styleUrls: ['./variable-editor.component.css']
})