This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Please see this as proposal on how to implement automatic/random colors for tags while keeping the current set of hard coded colors in place (at least in the frontend). Bear with me as I have even less Angular knowledge than Django and just tried to get away with as few changes as possible. :-) AIUI you want to change to a color picking system anyways in the future, which could also play well with this. fixes #51
- Loading branch information
1 parent
72a4ff0
commit 26784a5
Showing
10 changed files
with
116 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<span *ngIf="!clickable" class="badge" [style.background]="getColour().value" [style.color]="getColour().textColor">{{tag.name}}</span> | ||
<a [routerLink]="" [title]="linkTitle" *ngIf="clickable" class="badge" [style.background]="getColour().value" [style.color]="getColour().textColor">{{tag.name}}</a> | ||
<span *ngIf="!clickable" class="badge" [style.background]="getColour().id" [style.color]="getColour().textColor">{{tag.name}}</span> | ||
<a [routerLink]="" [title]="linkTitle" *ngIf="clickable" class="badge" [style.background]="getColour().id" [style.color]="getColour().textColor">{{tag.name}}</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Generated by Django 3.1.4 on 2020-12-02 21:43 | ||
|
||
from django.db import migrations, models | ||
|
||
COLOURS_OLD = { | ||
1: "#a6cee3", | ||
2: "#1f78b4", | ||
3: "#b2df8a", | ||
4: "#33a02c", | ||
5: "#fb9a99", | ||
6: "#e31a1c", | ||
7: "#fdbf6f", | ||
8: "#ff7f00", | ||
9: "#cab2d6", | ||
10: "#6a3d9a", | ||
11: "#b15928", | ||
12: "#000000", | ||
13: "#cccccc", | ||
} | ||
|
||
|
||
def forward(apps, schema_editor): | ||
Tag = apps.get_model('documents', 'Tag') | ||
|
||
for tag in Tag.objects.all(): | ||
colour_old_id = tag.colour_old | ||
rgb = COLOURS_OLD[colour_old_id] | ||
tag.colour = rgb | ||
tag.save() | ||
|
||
|
||
def reverse(apps, schema_editor): | ||
Tag = apps.get_model('documents', 'Tag') | ||
|
||
def _get_colour_id(rdb): | ||
for idx, rdbx in COLOURS_OLD.items(): | ||
if rdbx == rdb: | ||
return idx | ||
# Return colour 1 if we can't match anything | ||
return 1 | ||
|
||
for tag in Tag.objects.all(): | ||
colour_id = _get_colour_id(tag.colour) | ||
tag.colour_old = colour_id | ||
tag.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('documents', '1005_checksums'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='tag', | ||
old_name='colour', | ||
new_name='colour_old', | ||
), | ||
migrations.AddField( | ||
model_name='tag', | ||
name='colour', | ||
field=models.CharField(blank=True, max_length=7), | ||
), | ||
migrations.RunPython(forward, reverse), | ||
migrations.RemoveField( | ||
model_name='tag', | ||
name='colour_old', | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters