Skip to content

Commit 5887bb7

Browse files
lolimmlostclaude
andcommitted
refactor: Extract activity.html inline script to static/activity.js
Move the activityLog() Alpine factory (filter state + paginated /api/activity fetch + timestamp formatting) out of the inline <script> block into static/activity.js. Same load-order story as the other extractions: external script in {% block scripts %} executes during body parse, before Alpine's deferred init. This is the last template-level inline <script>. Combined with the previous extractions, the only remaining script tags in the rendered HTML are <script src="..."> references — no inline content. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent e43a29d commit 5887bb7

2 files changed

Lines changed: 50 additions & 49 deletions

File tree

src/web/static/activity.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Alpine factory for the activity log page. Owns the filter state, paginated
2+
// fetch against /api/activity, and timestamp formatting.
3+
function activityLog() {
4+
return {
5+
items: [],
6+
loading: true,
7+
page: 1,
8+
totalPages: 1,
9+
total: 0,
10+
filters: {
11+
search: '',
12+
action: '',
13+
arr: '',
14+
date_from: '',
15+
date_to: '',
16+
},
17+
async loadActivity() {
18+
this.loading = true;
19+
const params = new URLSearchParams({ page: this.page, per_page: 50 });
20+
if (this.filters.search) params.set('search', this.filters.search);
21+
if (this.filters.action) params.set('action', this.filters.action);
22+
if (this.filters.arr) params.set('arr', this.filters.arr);
23+
if (this.filters.date_from) params.set('date_from', this.filters.date_from);
24+
if (this.filters.date_to) params.set('date_to', this.filters.date_to);
25+
26+
try {
27+
const res = await fetch(`${rootPath}/api/activity?${params}`);
28+
const data = await res.json();
29+
this.items = data.items;
30+
this.total = data.total;
31+
this.totalPages = data.total_pages;
32+
} catch {
33+
this.items = [];
34+
}
35+
this.loading = false;
36+
},
37+
formatTime(ts) {
38+
if (!ts) return '';
39+
const d = new Date(ts + 'Z');
40+
return d.toLocaleString();
41+
},
42+
prevPage() {
43+
if (this.page > 1) { this.page--; this.loadActivity(); }
44+
},
45+
nextPage() {
46+
if (this.page < this.totalPages) { this.page++; this.loadActivity(); }
47+
},
48+
};
49+
}

src/web/templates/activity.html

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -99,53 +99,5 @@ <h2>Activity Log</h2>
9999
{% endblock %}
100100

101101
{% block scripts %}
102-
<script>
103-
function activityLog() {
104-
return {
105-
items: [],
106-
loading: true,
107-
page: 1,
108-
totalPages: 1,
109-
total: 0,
110-
filters: {
111-
search: '',
112-
action: '',
113-
arr: '',
114-
date_from: '',
115-
date_to: '',
116-
},
117-
async loadActivity() {
118-
this.loading = true;
119-
const params = new URLSearchParams({ page: this.page, per_page: 50 });
120-
if (this.filters.search) params.set('search', this.filters.search);
121-
if (this.filters.action) params.set('action', this.filters.action);
122-
if (this.filters.arr) params.set('arr', this.filters.arr);
123-
if (this.filters.date_from) params.set('date_from', this.filters.date_from);
124-
if (this.filters.date_to) params.set('date_to', this.filters.date_to);
125-
126-
try {
127-
const res = await fetch(`${rootPath}/api/activity?${params}`);
128-
const data = await res.json();
129-
this.items = data.items;
130-
this.total = data.total;
131-
this.totalPages = data.total_pages;
132-
} catch {
133-
this.items = [];
134-
}
135-
this.loading = false;
136-
},
137-
formatTime(ts) {
138-
if (!ts) return '';
139-
const d = new Date(ts + 'Z');
140-
return d.toLocaleString();
141-
},
142-
prevPage() {
143-
if (this.page > 1) { this.page--; this.loadActivity(); }
144-
},
145-
nextPage() {
146-
if (this.page < this.totalPages) { this.page++; this.loadActivity(); }
147-
},
148-
};
149-
}
150-
</script>
102+
<script src="{{ request.url_for('static', path='activity.js') }}"></script>
151103
{% endblock %}

0 commit comments

Comments
 (0)