Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 (jtd): Activity - add created_at #742

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ struct ActivityDetailsView: View {
Section("Information") {
RowView(label: "UUID", value: self.activity.id)
RowView(label: "Name", value: self.activity.name)
RowView(label: "Created at", value: self.activity.createdAt.description)
RowView(label: "Last edited at", value: self.activity.lastEditedAt.description)

RowView(label: "Status", value: self.activity.status == .published ? "published" : "draft")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ version: 1.0.0
uuid: 5A670B59EB214A6AA11AB39D64D63990
name: sample_1

created_at: "2024-02-28T14:49:32.982712"
last_edited_at: "2024-02-29T09:57:32.346571"
status: published

authors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ version: 1.0.0
uuid: 6102794F02D3423482E243BCBC7F8CA8
name: sample_2

created_at: "2024-02-28T14:49:34.312602"
last_edited_at: "2024-02-29T09:57:32.346571"
status: published

authors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ version: 1.0.0
uuid: E7EE9CA4B13B49AF96CD77A9DF90833B
name: sample_3

created_at: "2024-02-28T14:49:33.391679"
last_edited_at: "2024-02-29T11:06:01.695641"
status: published

authors:
Expand Down Expand Up @@ -42,7 +44,7 @@ l10n:
details:
icon: sample_3

title: Activité d'exemple 3
title: Activité d'exemple 3 - modified for testing - again without update of last_edited_at
subtitle: pour le développement

short_description: >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ version: 1.0.0
uuid: 81F6617499FE42ADB5B03B409462923E
name: sample_4

created_at: "2024-02-28T14:49:33.392801"
last_edited_at: "2024-02-29T09:57:32.346568"
status: published

authors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ version: 1.0.0
uuid: 725853C4DC7B4D84A45AA20385F389F1
name: sample_5

created_at: "2024-02-28T14:49:33.890955"
last_edited_at: "2024-02-29T09:57:32.346568"
status: published

authors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ version: 1.0.0
uuid: 2FE0B8BDD1B0497F87B32A390119DB98
name: sample_6

created_at: "2024-02-28T14:49:33.894132"
last_edited_at: "2024-02-29T09:57:32.346571"
status: published

authors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ version: 1.0.0
uuid: 0123456789ABCDEF0123456789ABCDEF # {{💡TO_DEFINE}}
name: activity_template # {{💡TO_DEFINE}}

created_at: "2024-02-28T14:49:32.973012"
last_edited_at: "2024-02-29T09:57:32.346568"
status: published

authors: # {{💡TO_DEFINE}}
Expand Down
3 changes: 3 additions & 0 deletions Modules/ContentKit/Sources/Activity/Activity+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public extension Activity {
uuid: E7EE9CA4B13B49AF96CD77A9DF90833B
name: mock_activity

created_at: 2024-02-28T12:53:48+00:00
last_edited_at: 2024-02-28T12:53:48+00:00

status: published

authors:
Expand Down
8 changes: 7 additions & 1 deletion Modules/ContentKit/Sources/Activity/Activity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

self.uuid = try container.decode(String.self, forKey: .uuid)
self.name = try container.decode(String.self, forKey: .name)
self.createdAt = try container.decode(Date.self, forKey: .createdAt)
self.lastEditedAt = try container.decode(Date.self, forKey: .lastEditedAt)
self.status = try container.decode(Status.self, forKey: .status)

self.authors = try container.decode([String].self, forKey: .authors)
Expand All @@ -38,13 +40,15 @@

public let uuid: String
public let name: String
public let createdAt: Date
public let lastEditedAt: Date
public let status: Status

public let authors: [String] // TODO: (@ladislas) - implement authors

Check warning on line 47 in Modules/ContentKit/Sources/Activity/Activity.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) - implement author...) (todo)
public let skills: [String] // TODO: (@ladislas) - implement skills

Check warning on line 48 in Modules/ContentKit/Sources/Activity/Activity.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) - implement skills) (todo)
public let hmi: [String] // TODO: (@ladislas) - implement hmi

Check warning on line 49 in Modules/ContentKit/Sources/Activity/Activity.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) - implement hmi) (todo)
public let types: [String] // TODO: (@ladislas) - implement types

Check warning on line 50 in Modules/ContentKit/Sources/Activity/Activity.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) - implement types) (todo)
public let tags: [String] // TODO: (@ladislas) - implement tags

Check warning on line 51 in Modules/ContentKit/Sources/Activity/Activity.swift

View workflow job for this annotation

GitHub Actions / swiftlint

TODOs should be resolved ((@ladislas) - implement tags) (todo)

public let locales: [Locale]
public let l10n: [LocalizedDetails]
Expand Down Expand Up @@ -72,12 +76,14 @@
private enum CodingKeys: String, CodingKey {
case uuid
case name
case createdAt = "created_at"
case lastEditedAt = "last_edited_at"
case status
case authors
case skills
case hmi
case types
case tags
case status
case locales
case l10n
case exercicesPayload = "exercises_payload"
Expand Down
6 changes: 6 additions & 0 deletions Specs/jtd/activity.jtd.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
"name": {
"type": "string"
},
"created_at": {
"type": "string"
},
"last_edited_at": {
"type": "string"
},
"status": {
"ref": "$status"
},
Expand Down
84 changes: 81 additions & 3 deletions Tools/Hooks/check_yaml_content_activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@
import uuid
import sys
from pathlib import Path
from datetime import datetime, timedelta
import ruamel.yaml


JTD_SCHEMA = "Specs/jtd/activity.jtd.json"
SKILLS_FILE = "Modules/ContentKit/Resources/Content/definitions/skills.yml"
CONTENTKIT_DIRECTORY = "Modules/ContentKit/Resources/Content"

CREATED_AT_INDEX = 3
LAST_EDITED_AT_INDEX = 4
DATE_NOW_TIMESTAMP = ruamel.yaml.scalarstring.DoubleQuotedScalarString(
datetime.now().isoformat()
)


#
# Mark: - Functions
Expand Down Expand Up @@ -61,11 +68,44 @@ def find_skill_ids(data, ids):
return ids


def check_content_activity(filename):
"""Check the content of a YAML file for an activity"""
# ? Create a YAML object
def is_file_modified(file_path):
"""Check if a file is modified and/or staged for commit"""
result = subprocess.run(
["git", "status", "--porcelain", file_path],
capture_output=True,
text=True,
check=False,
)

output = result.stdout.strip()

if output:
# Check for modifications in both staged (index) and work tree
# Staged modifications: first letter is not ' ' (space)
# Work tree modifications: second letter is 'M'
# This covers added (A), modified (M), deleted (D), renamed (R), etc.
status_code = output[:2]
if status_code[0] != " " or status_code[1] == "M":
return True

return False


def create_yaml_object():
"""Create a YAML object"""
yaml = ruamel.yaml.YAML(typ="rt")
yaml.indent(mapping=2, sequence=4, offset=2)
yaml.preserve_quotes = True
yaml.representer.add_representer(
type(None),
lambda dumper, data: dumper.represent_scalar("tag:yaml.org,2002:null", "null"),
)
return yaml


def check_content_activity(filename):
"""Check the content of a YAML file for an activity"""
yaml = create_yaml_object()

file_is_valid = True

Expand All @@ -89,6 +129,44 @@ def check_content_activity(filename):
print(f"uuid: {data['uuid']}")
file_is_valid = False

# ? Check created_at is present
if "created_at" not in data:
print(f"\n❌ Missing key created_at in {filename}")
print(f"Add created_at: {DATE_NOW_TIMESTAMP}")
if "name" in data and "status" in data:
data.insert(CREATED_AT_INDEX, "created_at", DATE_NOW_TIMESTAMP)
with open(filename, "w", encoding="utf8") as file:
yaml.dump(data, file)

file_is_valid = False

# ? Check last_edited_at is present
if "last_edited_at" not in data:
print(f"\n❌ Missing key last_edited_at in {filename}")
print(f"Add last_edited_at: {DATE_NOW_TIMESTAMP}")
if "name" in data and "status" in data:
data.insert(LAST_EDITED_AT_INDEX, "last_edited_at", DATE_NOW_TIMESTAMP)
with open(filename, "w", encoding="utf8") as file:
yaml.dump(data, file)

file_is_valid = False

# ? Update last_edited_at if DATE_NOW_TIMESTAMP is more recent with a threshold of 1 minute
if is_file_modified(filename) and "last_edited_at" in data:
last_edited_at = datetime.fromisoformat(data["last_edited_at"])
one_minute_ago = datetime.fromisoformat(DATE_NOW_TIMESTAMP) - timedelta(
minutes=1
)
if last_edited_at < one_minute_ago:
print(f"\n❌ last_edited_at in {filename} is not up to date")
print(f"last_edited_at: {last_edited_at}")
print(f"Update last_edited_at: {DATE_NOW_TIMESTAMP}")
data["last_edited_at"] = DATE_NOW_TIMESTAMP
with open(filename, "w", encoding="utf8") as file:
yaml.dump(data, file)

file_is_valid = False

# ? Check schema validation with ajv
os.environ["FORCE_COLOR"] = "true"
cmd = (
Expand Down
Loading