star rating script - update?

Post Reply
weidmic
moderator
Posts: 4503
Joined: 04 Dec 06 22:21

star rating script - update?

Post by weidmic » 30 Nov 18 18:04

Hert,

you have been so nice to provide a script for the star rating for the custom thumb info.
Now that you have introduced the support for a 'reject' rating, I would love to see the script updated :wink:

Code: Select all

%code
    var
      ACatItem: TCatalogItem;
      ARatingAnchorHref: String;
      ARatingNoColor: String;
      ARatingColor: String;
      ARatingStar: String;
      ARatingOnStar: String;
      ARatingOffStar: String;
      i: Integer;
    begin
      result := '';

      ARatingNoColor := '#CFFF0000'; //#### red color 
      ARatingColor   := '#CFFFFF00'; //#### Yellow color for rating stars
      ARatingStar    := 'M 3.03,4.19883 L 2.996,4.22354 L 3.00909,4.26369 L 2.97501,4.2389 L 2.94086,4.26369 L 2.95394,4.22354 L 2.92,4.19883 L 2.96193,4.19883 L 2.97501,4.1589 L 2.98801,4.19883 L 3.03,4.19883 Z ';

      ARatingAnchorHref := 'code:' +
'  function IsImageItemSelected: Boolean; ' +
'  var ' +
'    i: Integer; ' +
'  begin ' +
'    result := False; ' +
'    for i := 0 to Selected.Count - 1 do ' + 
'    begin ' +
'       if Selected.Items[i].GUID = ImageItem.GUID then ' +
'       begin ' +
'         result := True; ' +
'         exit; ' +
'       end; ' +
'     end; ' +
'  end; ' +
'var ' +
'  i: Integer; ' +
'  ACatItem: TCatalogItem; ' +
'begin ' +
'  if not IsImageItemSelected then ' +
'  begin ' +
'    Selected.Clear; ' +
'    Selected.Add(ImageItem); ' +
'  end; ' +
'' +
'  for i := 0 to Selected.Count - 1 do ' +
'  begin ' +
'     ACatItem := TCatalogItem.Create(nil); ' +
'     if PublicCatalog.FindItemCombinedByGUID(Selected.Items[i].GUID, ACatItem) then ' +
'     begin ' +
'       ACatItem.Rating := #rating#; ' +
'       if PublicCatalog.StoreItemToDataBase(ACatItem, False) then ' +
'         PublicCatalog.UpdateItemSyncState(ACatItem, [], [idcsDBXmp], False, True); ' +
'     end; ' +
'     ACatItem.Free; ' +
'  end; ' +
'end; ' +
'';

      ARatingNoOnStar   := '<a href="' + ARatingAnchorHref + '"><img title="no rating" size="22" path="' + ARatingStar + '" pathfillcolor="' + ARatingNoColor + '" pathstrokestyle="solid" pathstrokecolor="' + ARatingNoColor + '"></a>';
      ARatingNoOffStar  := '<a href="' + ARatingAnchorHref + '"><img size="22" path="' + ARatingStar + '" pathfillstyle="none" pathstrokestyle="solid" pathstrokecolor="' + ARatingNoColor  + '"></a>';
      ARatingOnStar     := '<a href="' + ARatingAnchorHref + '"><img size="22" path="' + ARatingStar + '" pathfillcolor="' + ARatingColor + '" pathstrokestyle="solid" pathstrokecolor="' + ARatingColor + '"></a>';
      ARatingOffStar    := '<a href="' + ARatingAnchorHref + '"><img size="22" path="' + ARatingStar + '" pathfillstyle="none" pathstrokestyle="solid" pathstrokecolor="' + ARatingColor + '"></a>';

      ACatItem := TCatalogItem.Create(nil);
      if Catalog.FindImageCombined (ImageItem, ACatItem, False, vptNone) then
      begin
        result := result + '<font color="'+ ARatingColor +'"><ind y="2">';

        if ACatItem.Rating > 0 then
          result := result + StrTran(ARatingNoOnStar, '#rating#', '0');
        else
          result := result + StrTran(ARatingNoOffStar, '#rating#', '0');

        for i := 1 to ACatItem.Rating do
          result := result + StrTran(ARatingOnStar, '#rating#', IntToStr(i));
        for i := ACatItem.Rating + 1 to 5 do
          result := result + StrTran(ARatingOffStar, '#rating#', IntToStr(i));
        result := result + '</ind></font>';
      end;
      ACatItem.Free;
    end;
    %/code
<a href="code:
var
  AItem: TCatalogItem;
begin
  AItem := TCatalogItem.Create(nil);
  try
    if PublicCatalog.FindItemCombinedByGUID(ImageItem.GUID, AItem) then
    begin
      PublicCatalog.WriteItemToXMPAdvanced(AItem, PublicOptions.XMPSyncWriteSettings, True, PublicOptions.XMPSyncWriteSettings.StoreCached);
    end;
  finally
    AItem.Free
  end;
end;"><FONT color="#FF0000">Save</a>
If you don't mind, I would like to ask you to update the script in order to reflect the reject rating.

Best Regards,
Michael
Attachments
starrating.JPG
starrating.JPG (23.38 KiB) Viewed 475 times
PSUServer 4.x, PostgreSQL 10.x
My homepage http://www.michaelweidner.com
PSU Tips and Tricks http://www.michaelweidner.com/WP/psu/

Hert
Posts: 21556
Joined: 13 Sep 03 7:24

Re: star rating script - update?

Post by Hert » 01 Dec 18 9:25

I've updated the version of the script in the repository. With Custom Thumbs, use the drop down in the line -> From Repository -> Functional Rating Bar
FunctionalRatingBar.png
FunctionalRatingBar.png (52.66 KiB) Viewed 448 times
Apparently you were using a customized version of the script. You should add that "Save" option that you've added at some point
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

weidmic
moderator
Posts: 4503
Joined: 04 Dec 06 22:21

Re: star rating script - update?

Post by weidmic » 03 Dec 18 13:53

Thank you! Much appreciated...

Michael
PSUServer 4.x, PostgreSQL 10.x
My homepage http://www.michaelweidner.com
PSU Tips and Tricks http://www.michaelweidner.com/WP/psu/

Larry56
Posts: 419
Joined: 05 Jul 10 6:57

Re: star rating script - update?

Post by Larry56 » 03 Dec 18 18:07

I like the ability to change all stars at once with the red star in the old script. I thought I could customize the new one with reject option but this looks way too complicated for me.

Can anyone tell me which part of the old script I can copy and past into the new? Or does it have to be a whole new script?

Hert
Posts: 21556
Joined: 13 Sep 03 7:24

Re: star rating script - update?

Post by Hert » 04 Dec 18 8:29

The red icon was to revoke a rating. Now you should click the active rating to remove it again.
e.g. a 3 star rated image. Click the 3 star rating to revoke the rating
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

Larry56
Posts: 419
Joined: 05 Jul 10 6:57

Re: star rating script - update?

Post by Larry56 » 04 Dec 18 17:37

Thank you.

Post Reply