1616import Masonry from 'masonry-layout' ;
1717import { Chart , registerables } from 'chart.js' ;
1818import { getRemoteHashes , verifyHashes } from './api' ;
19- import { addElement } from '../../../assets/src/utils' ;
19+ import { addElement , TranslationService } from '../../../assets/src/utils' ;
2020
21- export const renderVisitorCharts = async ( ) => {
21+ export const renderVisitorCharts = async ( ) : Promise < void > => {
2222 const context = document . getElementById ( 'pmf-chart-visits' ) as HTMLCanvasElement | null ;
2323
2424 if ( context ) {
@@ -63,15 +63,12 @@ export const renderVisitorCharts = async () => {
6363 display : true ,
6464 text : 'Visitors' ,
6565 } ,
66- ticks : {
67- beginAtZero : true ,
68- } ,
6966 } ,
7067 } ,
7168 } ,
7269 } ) ;
7370
74- const getData = async ( ) => {
71+ const getData = async ( ) : Promise < void > => {
7572 try {
7673 const response = await fetch ( './api/dashboard/visits' , {
7774 method : 'GET' ,
@@ -102,7 +99,7 @@ export const renderVisitorCharts = async () => {
10299 }
103100} ;
104101
105- export const renderTopTenCharts = async ( ) => {
102+ export const renderTopTenCharts = async ( ) : Promise < void > => {
106103 const context = document . getElementById ( 'pmf-chart-topten' ) as HTMLCanvasElement | null ;
107104
108105 if ( context ) {
@@ -150,22 +147,19 @@ export const renderTopTenCharts = async () => {
150147 title : {
151148 display : false ,
152149 } ,
153- ticks : {
154- beginAtZero : true ,
155- } ,
156150 } ,
157151 } ,
158152 } ,
159153 } ) ;
160154
161155 const dynamicColors = ( ) : string => {
162- const r = Math . floor ( Math . random ( ) * 255 ) ;
163- const g = Math . floor ( Math . random ( ) * 255 ) ;
164- const b = Math . floor ( Math . random ( ) * 255 ) ;
156+ const r : number = Math . floor ( Math . random ( ) * 255 ) ;
157+ const g : number = Math . floor ( Math . random ( ) * 255 ) ;
158+ const b : number = Math . floor ( Math . random ( ) * 255 ) ;
165159 return 'rgb(' + r + ',' + g + ',' + b + ')' ;
166160 } ;
167161
168- const getData = async ( ) => {
162+ const getData = async ( ) : Promise < void > => {
169163 try {
170164 const response = await fetch ( './api/dashboard/topten' , {
171165 method : 'GET' ,
@@ -180,7 +174,7 @@ export const renderTopTenCharts = async () => {
180174 if ( response . status === 200 ) {
181175 const topTen : { question : string ; visits : number } [ ] = await response . json ( ) ;
182176
183- topTen . forEach ( ( faq ) => {
177+ topTen . forEach ( ( faq : { question : string ; visits : number } ) : void => {
184178 doughnutChart . data . labels ! . push ( faq . question ) ;
185179 doughnutChart . data . datasets [ 0 ] . data . push ( faq . visits ) ;
186180 colors . push ( dynamicColors ( ) ) ;
@@ -197,9 +191,9 @@ export const renderTopTenCharts = async () => {
197191 }
198192} ;
199193
200- export const getLatestVersion = async ( ) => {
201- const loader = document . getElementById ( 'version-loader' ) ;
202- const versionText = document . getElementById ( 'phpmyfaq-latest-version' ) ;
194+ export const getLatestVersion = async ( ) : Promise < void > => {
195+ const loader = document . getElementById ( 'version-loader' ) as HTMLDivElement ;
196+ const versionText = document . getElementById ( 'phpmyfaq-latest-version' ) as HTMLDivElement ;
203197
204198 if ( loader && versionText ) {
205199 loader . classList . remove ( 'd-none' ) ;
@@ -263,28 +257,31 @@ export const getLatestVersion = async () => {
263257 }
264258} ;
265259
266- export const handleVerificationModal = async ( ) => {
267- const verificationModal = document . getElementById ( 'verificationModal' ) ;
260+ export const handleVerificationModal = async ( ) : Promise < void > => {
261+ const verificationModal = document . getElementById ( 'verificationModal' ) as HTMLDivElement ;
262+ const Translator = new TranslationService ( ) ;
268263 if ( verificationModal ) {
269- verificationModal . addEventListener ( 'show.bs.modal' , async ( ) => {
270- const spinner = document . getElementById ( 'pmf-verification-spinner' ) ;
271- const version = verificationModal . getAttribute ( 'data-pmf-current-version' ) ;
272- const updates = document . getElementById ( 'pmf-verification-updates' ) ;
264+ verificationModal . addEventListener ( 'show.bs.modal' , async ( ) : Promise < void > => {
265+ const spinner = document . getElementById ( 'pmf-verification-spinner' ) as HTMLDivElement ;
266+ const version = verificationModal . getAttribute ( 'data-pmf-current-version' ) as string ;
267+ const updates = document . getElementById ( 'pmf-verification-updates' ) as HTMLDivElement ;
268+ const language : string = document . documentElement . lang ;
269+ await Translator . loadTranslations ( language ) ;
273270 if ( spinner && updates && version ) {
274271 spinner . classList . remove ( 'd-none' ) ;
275- updates . innerText = 'Fetching verification hashes from api.phpmyfaq.de...' ;
276- const remoteHashes = await getRemoteHashes ( version ) ;
277- updates . innerText = 'Checking hashes with installation files...' ;
272+ updates . innerText = Translator . translate ( 'msgFetchingHashes' ) ;
273+ const remoteHashes = ( await getRemoteHashes ( version ) ) as Record < string , string > ;
274+ updates . innerText = Translator . translate ( 'msgCheckHashes' ) ;
278275 const issues = await verifyHashes ( remoteHashes ) ;
279276
280277 if ( typeof issues !== 'object' ) {
281278 console . error ( 'Invalid JSON data provided.' ) ;
282279 }
283280
284- const ul = document . createElement ( 'ul' ) ;
281+ const ul = document . createElement ( 'ul' ) as HTMLUListElement ;
285282 for ( const [ filename , hashValue ] of Object . entries ( issues ) ) {
286- const li = document . createElement ( 'li' ) ;
287- li . textContent = `Filename : ${ filename } , Hash Value : ${ hashValue } ` ;
283+ const li = document . createElement ( 'li' ) as HTMLLIElement ;
284+ li . textContent = `${ Translator . translate ( 'msgAttachmentsFilename' ) } : ${ filename } , Hash: ${ hashValue } ` ;
288285 ul . appendChild ( li ) ;
289286 }
290287
@@ -295,8 +292,8 @@ export const handleVerificationModal = async () => {
295292 }
296293} ;
297294
298- window . onload = ( ) => {
299- const masonryElement = document . querySelector ( '.masonry-grid' ) ;
295+ window . onload = ( ) : void => {
296+ const masonryElement = document . querySelector ( '.masonry-grid' ) as HTMLElement ;
300297 if ( masonryElement ) {
301298 new Masonry ( masonryElement , { columnWidth : 0 } ) ;
302299 }
0 commit comments