Skip to content

Commit 8c9b6b1

Browse files
committed
Added Eis[kalt] Ice Creams recipe
1 parent ad62fd0 commit 8c9b6b1

File tree

7 files changed

+111
-1
lines changed

7 files changed

+111
-1
lines changed

src/main.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Plugin } from 'obsidian';
22
import { MarkdownTableConverter } from './markdown/MarkdownTableConverter';
33
import { MarkdownTableFactory } from './markdown/MarkdownTableFactory';
44
import { PluginUpdateCommandFactory } from './plugin/PluginUpdateCommandFactory';
5+
import { EisKaltIceCreamsRecipe } from './recipes/eis_kalt_ice_creams/EisKaltIceCreamsRecipe';
56
import { GelateriaLaRomanaDel1947GelatiRecipe } from './recipes/gelateria_la_romana_dal_1947_gelati/GelateriaLaRomanaDel1947GelatiRecipe';
67
import { HanayamaHuzzlesRecipe } from './recipes/hanayama_huzzles/HanayamaHuzzlesRecipe';
78
import { IQPuzzlesRecipe } from './recipes/iq_puzzles/IQPuzzlesRecipe';
@@ -64,6 +65,20 @@ export default class TrackALotPlugin extends Plugin {
6465

6566
this.addCommand(command);
6667
}
68+
69+
if (settingsManager.settings.eisKaltIceCreams.isActive) {
70+
const command = commandFactory.command(
71+
EisKaltIceCreamsRecipe.NAME,
72+
new EisKaltIceCreamsRecipe(
73+
markdownTableFactory,
74+
markdownTableConverter,
75+
trackablesUpdater
76+
),
77+
settingsManager.settings.eisKaltIceCreams
78+
);
79+
80+
this.addCommand(command);
81+
}
6782
}
6883

6984
onunload() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Trackable } from 'src/tracking/Trackable';
2+
import { NameAndImage } from '../name_and_image/NameAndImage';
3+
4+
export class EisKaltIceCream implements NameAndImage {
5+
readonly identifier: string;
6+
7+
constructor(
8+
public readonly name: string,
9+
public readonly imageLink: string,
10+
public readonly status = ''
11+
) {
12+
this.identifier = name;
13+
}
14+
15+
withStatus(newStatus: string): Trackable {
16+
return new EisKaltIceCream(this.name, this.imageLink, newStatus);
17+
}
18+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { MarkdownTableConverter } from 'src/markdown/MarkdownTableConverter';
2+
import { MarkdownTableFactory } from 'src/markdown/MarkdownTableFactory';
3+
import { TrackablesUpdater } from 'src/tracking/TrackablesUpdater';
4+
import { NameAndImageRecipe } from '../name_and_image/NameAndImageRecipe';
5+
import { Recipe } from '../Recipe';
6+
import { EisKaltIceCream } from './EisKaltIceCream';
7+
8+
export class EisKaltIceCreamsRecipe implements Recipe {
9+
static readonly NAME = 'Eis[kalt] Ice Creams';
10+
static readonly WEBPAGE = 'https://inghetata-brasov.ro';
11+
12+
static readonly #SCRAPE_URL = 'https://inghetata-brasov.ro/inghetata-noastra/';
13+
14+
private readonly recipe;
15+
16+
constructor(
17+
markdownTableFactory: MarkdownTableFactory,
18+
markdownTableConverter: MarkdownTableConverter,
19+
trackablesUpdater: TrackablesUpdater
20+
) {
21+
this.recipe = new NameAndImageRecipe<EisKaltIceCream>(
22+
EisKaltIceCreamsRecipe.NAME,
23+
[EisKaltIceCreamsRecipe.#SCRAPE_URL],
24+
markdownTableFactory,
25+
markdownTableConverter,
26+
trackablesUpdater,
27+
content => {
28+
return Array.from(content.querySelectorAll('.full_width_inner .vc_column_container.vc_col-sm-4'));
29+
},
30+
product => {
31+
const title = product.querySelector('.wpb_text_column h2')?.textContent;
32+
33+
if (title == null) {
34+
return null;
35+
}
36+
37+
const name = title;
38+
39+
const image = product.querySelector('.wpb_single_image .vc_single_image-img');
40+
const imageLink = image != null ? (image as HTMLImageElement).src : '';
41+
42+
return new EisKaltIceCream(name, imageLink);
43+
},
44+
(name, imageLink, status) => {
45+
return new EisKaltIceCream(name, imageLink, status);
46+
}
47+
);
48+
}
49+
50+
updatedListInContent(content: string): Promise<string> {
51+
return this.recipe.updatedListInContent(content);
52+
}
53+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { RecipeSettingsToggleable } from 'src/settings/data/RecipeSettingsToggleable';
2+
3+
export class EisKaltIceCreamsRecipeSettings implements RecipeSettingsToggleable {
4+
isActive: boolean;
5+
}

src/settings/RecipesSettingsTab.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { App, Plugin, PluginSettingTab, Setting } from 'obsidian';
22
import 'src/html/HTMLElementExtensions';
3+
import { EisKaltIceCreamsRecipe } from 'src/recipes/eis_kalt_ice_creams/EisKaltIceCreamsRecipe';
4+
import { EisKaltIceCreamsRecipeSettings } from 'src/recipes/eis_kalt_ice_creams/EisKaltIceCreamsRecipeSettings';
35
import { GelateriaLaRomanaDel1947GelatiRecipe } from 'src/recipes/gelateria_la_romana_dal_1947_gelati/GelateriaLaRomanaDel1947GelatiRecipe';
46
import { GelateriaLaRomanaDel1947GelatiRecipeSettings } from 'src/recipes/gelateria_la_romana_dal_1947_gelati/GelateriaLaRomanaDel1947GelatiRecipeSettings';
57
import { HanayamaHuzzlesRecipe } from 'src/recipes/hanayama_huzzles/HanayamaHuzzlesRecipe';
@@ -30,6 +32,7 @@ export class RecipesSettingsTab extends PluginSettingTab {
3032
this.#addHanayamaHuzzlesSettings(settings.hanayamaHuzzles, settingsAdder);
3133
this.#addIQPuzzlesSettings(settings.iqPuzzles, settingsAdder);
3234
this.#addGelateriaLaRomanaDel1947GelatiSettings(settings.gelateriaLaRomanaDel1947Gelati, settingsAdder);
35+
this.#addEisKaltIceCreamsSettings(settings.eisKaltIceCreams, settingsAdder);
3336
}
3437

3538
#addHanayamaHuzzlesSettings(settings: HanayamaHuzzlesRecipeSettings, settingsAdder: SettingsAdder) {
@@ -79,6 +82,18 @@ export class RecipesSettingsTab extends PluginSettingTab {
7982
);
8083
}
8184

85+
#addEisKaltIceCreamsSettings(settings: EisKaltIceCreamsRecipeSettings, settingsAdder: SettingsAdder) {
86+
const adder = new RecipeSettingsAdder(this.containerEl, settingsAdder);
87+
adder.add(EisKaltIceCreamsRecipe.NAME, EisKaltIceCreamsRecipe.WEBPAGE);
88+
adder.activate(
89+
() => { return settings.isActive; },
90+
async value => {
91+
settings.isActive = value;
92+
await this.settingsManager.saveSettings();
93+
}
94+
);
95+
}
96+
8297
#setSettingsEnabled(settings: Setting[], enabled: boolean) {
8398
settings.forEach(setting => {
8499
setting.setDisabled(!enabled);

src/settings/SettingsManager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Plugin } from 'obsidian';
2+
import { EisKaltIceCreamsRecipeSettings } from 'src/recipes/eis_kalt_ice_creams/EisKaltIceCreamsRecipeSettings';
23
import { GelateriaLaRomanaDel1947GelatiRecipeSettings } from 'src/recipes/gelateria_la_romana_dal_1947_gelati/GelateriaLaRomanaDel1947GelatiRecipeSettings';
34
import { HanayamaHuzzlesRecipeSettings } from 'src/recipes/hanayama_huzzles/settings/HanayamaHuzzlesRecipeSettings';
45
import { IQPuzzlesRecipeSettings } from 'src/recipes/iq_puzzles/IQPuzzlesRecipeSettings';
@@ -8,7 +9,8 @@ export class SettingsManager {
89
static readonly #DEFAULT_SETTINGS: Partial<RecipesSettings> = {
910
hanayamaHuzzles: new HanayamaHuzzlesRecipeSettings(),
1011
iqPuzzles: new IQPuzzlesRecipeSettings(),
11-
gelateriaLaRomanaDel1947Gelati: new GelateriaLaRomanaDel1947GelatiRecipeSettings()
12+
gelateriaLaRomanaDel1947Gelati: new GelateriaLaRomanaDel1947GelatiRecipeSettings(),
13+
eisKaltIceCreams: new EisKaltIceCreamsRecipeSettings()
1214
};
1315

1416
settings: RecipesSettings;

src/settings/data/RecipesSettings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { EisKaltIceCreamsRecipeSettings } from 'src/recipes/eis_kalt_ice_creams/EisKaltIceCreamsRecipeSettings';
12
import { GelateriaLaRomanaDel1947GelatiRecipeSettings } from 'src/recipes/gelateria_la_romana_dal_1947_gelati/GelateriaLaRomanaDel1947GelatiRecipeSettings';
23
import { HanayamaHuzzlesRecipeSettings } from 'src/recipes/hanayama_huzzles/settings/HanayamaHuzzlesRecipeSettings';
34
import { IQPuzzlesRecipeSettings } from 'src/recipes/iq_puzzles/IQPuzzlesRecipeSettings';
@@ -6,4 +7,5 @@ export interface RecipesSettings {
67
hanayamaHuzzles: HanayamaHuzzlesRecipeSettings;
78
iqPuzzles: IQPuzzlesRecipeSettings;
89
gelateriaLaRomanaDel1947Gelati: GelateriaLaRomanaDel1947GelatiRecipeSettings;
10+
eisKaltIceCreams: EisKaltIceCreamsRecipeSettings;
911
}

0 commit comments

Comments
 (0)