@@ -1948,6 +1948,7 @@ export class Image extends CardElement {
19481948 static readonly selectActionProperty = new ActionProperty ( Versions . v1_1 , "selectAction" , [
19491949 "Action.ShowCard"
19501950 ] ) ;
1951+ static readonly shouldForceLoadProperty = new BoolProperty ( Versions . v1_6 , "forceLoad" , false ) ;
19511952
19521953 protected populateSchema ( schema : SerializableObjectSchema ) {
19531954 super . populateSchema ( schema ) ;
@@ -1981,6 +1982,9 @@ export class Image extends CardElement {
19811982 @property ( Image . selectActionProperty )
19821983 selectAction ?: Action ;
19831984
1985+ @property ( Image . shouldForceLoadProperty )
1986+ forceLoad : boolean ;
1987+
19841988 //#endregion
19851989
19861990 private applySize ( element : HTMLElement ) {
@@ -2140,7 +2144,7 @@ export class Image extends CardElement {
21402144 imageElement . style . backgroundColor = backgroundColor ;
21412145 }
21422146
2143- imageElement . src = < string > this . preProcessPropertyValue ( Image . urlProperty ) ;
2147+ this . setImageSource ( imageElement ) ;
21442148
21452149 const altTextProperty = this . preProcessPropertyValue ( Image . altTextProperty ) ;
21462150 if ( altTextProperty ) {
@@ -2188,6 +2192,45 @@ export class Image extends CardElement {
21882192 getResourceInformation ( ) : IResourceInformation [ ] {
21892193 return this . url ? [ { url : this . url , mimeType : "image" } ] : [ ] ;
21902194 }
2195+
2196+ private setImageSource ( imageElement : HTMLImageElement ) : void {
2197+ const imageForceLoader : ImageForceLoader = new ImageForceLoader ( this . forceLoad , this . url ) ;
2198+ imageForceLoader . configureImage ( this ) ;
2199+ imageElement . src = < string > this . preProcessPropertyValue ( Image . urlProperty ) ;
2200+ imageForceLoader . resetImage ( this ) ;
2201+ }
2202+ }
2203+
2204+ // configures Image element to fetch a new image data from url source instead of relying on cache
2205+ // currently rudimentary refreshing scheme is used
2206+ // by attaching unique query string to url, we bypass the cache usage
2207+ class ImageForceLoader {
2208+ private uniqueHash : string ;
2209+ public readonly urlWithForceLoadOption : string ;
2210+ constructor (
2211+ readonly doForceLoad : boolean ,
2212+ readonly url : string | undefined ,
2213+ )
2214+ {
2215+ if ( url && url . length && doForceLoad ) {
2216+ // we can do better by appending unique key such as uuid instead of epoch
2217+ // however the current usage is for front-end ui and networking,
2218+ // since ui is running in single main thread, this is sufficient mechanism
2219+ // without needing to depend on external library for our small use cases.
2220+ this . uniqueHash = '?' + Date . now ( ) ;
2221+ this . urlWithForceLoadOption = url + this . uniqueHash ;
2222+ }
2223+ }
2224+
2225+ public configureImage ( image : Image ) : void {
2226+ if ( this . urlWithForceLoadOption && this . urlWithForceLoadOption . length ) {
2227+ image . url = this . urlWithForceLoadOption ;
2228+ }
2229+ }
2230+
2231+ public resetImage ( image : Image ) : void {
2232+ image . url = this . url ;
2233+ }
21912234}
21922235
21932236export abstract class CardElementContainer extends CardElement {
0 commit comments