NotificationInbox

TsgcHTMLComponent_NotificationInbox: 읽지 않음 배지가 있는 종 아이콘과 한 사용자의 알림을 보여 주는 드롭다운 목록으로, Delphi, C++ Builder 및 .NET에서 사용할 수 있습니다. 행은 애플리케이션이 보관하고, 컴포넌트는 이를 렌더링합니다.

TsgcHTMLComponent_NotificationInbox

라이브러리는 아무것도 저장하지 않습니다. 애플리케이션은 보관하고 있는 행으로 OnLoadNotifications에 응답하고, 사용자가 한 일은 OnMarkReadOnMarkAllRead를 통해 전달받아 이를 유지할 수 있습니다. 컴포넌트는 UI를 렌더링할 뿐 권한 부여를 강제하지 않습니다. 모든 에디션에서 WebSocket 또는 서버 전송 이벤트를 통해 동작합니다.

컴포넌트 클래스

TsgcHTMLComponent_NotificationInbox(유닛 sgcHTML_Component_NotificationInbox)

렌더링

Bootstrap 드롭다운 마크업: 종 아이콘, 읽지 않음 배지, 목록

언어

Delphi, C++ Builder, .NET

생성하고, 세 가지 이벤트를 처리하고, 액션을 라우팅하기

수신함에 InboxID를 지정하고, OnLoadNotifications에서 자체 저장소로 채우고, 사용자가 한 일은 OnMarkReadOnMarkAllRead에서 유지하며, 게시된 액션은 세션에서 가져온 사용자와 함께 ProcessAction으로 라우팅합니다.

uses
  sgcHTML_Session, sgcHTML_Component_NotificationInbox;

var
  oInbox: TsgcHTMLComponent_NotificationInbox;
begin
  oInbox := TsgcHTMLComponent_NotificationInbox.Create(nil);
  try
    oInbox.InboxID := 'inbox';
    oInbox.Title := 'Notifications';
    oInbox.MaxItems := 10;
    oInbox.OnLoadNotifications := InboxLoad;
    oInbox.OnMarkRead := InboxMarkRead;
    oInbox.OnMarkAllRead := InboxMarkAllRead;

    // the user comes from the session, never from the form
    oInbox.LoadNotifications(sgcHTMLRequestSession.UserID);
    Response := oInbox.HTML;   // bell, unread badge and dropdown
  finally
    oInbox.Free;
  end;
end;

// the application owns the rows: fill the list, newest first
procedure TMain.InboxLoad(Sender: TObject; const aUserID: string;
  aList: TsgcHTMLInboxItems);
begin
  with aList.Add do
  begin
    Id := '1042';
    Title := 'New order';
    Text := 'Order #1042 was placed.';
    Timestamp := '2 min ago';
    Read := False;
  end;
end;

procedure TMain.InboxMarkRead(Sender: TObject; const aUserID,
  aNotificationID: string);
begin
  // persist it, after checking that aUserID owns aNotificationID
end;

// in the message handler that receives the actions the inbox posts
if oInbox.ProcessAction(vUser, vAction, vNotificationID) then
  oHTMX.PushFragment(vGuid, oInbox.GetListFragmentHTML +
    oInbox.GetBadgeFragmentHTML);
// includes: sgcHTML_Session.hpp, sgcHTML_Component_NotificationInbox.hpp

TsgcHTMLComponent_NotificationInbox *oInbox = new TsgcHTMLComponent_NotificationInbox(NULL);
try
{
  oInbox->InboxID = "inbox";
  oInbox->Title = "Notifications";
  oInbox->MaxItems = 10;
  oInbox->OnLoadNotifications = InboxLoad;
  oInbox->OnMarkRead = InboxMarkRead;
  oInbox->OnMarkAllRead = InboxMarkAllRead;

  // the user comes from the session, never from the form
  oInbox->LoadNotifications(sgcHTMLRequestSession()->UserID);
  String html = oInbox->HTML;   // bell, unread badge and dropdown
}
__finally
{
  delete oInbox;
}

// the application owns the rows: fill the list, newest first
void __fastcall TMain::InboxLoad(TObject *Sender, const String aUserID,
  TsgcHTMLInboxItems *aList)
{
  TsgcHTMLInboxItem *item = aList->Add();
  item->Id = "1042";
  item->Title = "New order";
  item->Text = "Order #1042 was placed.";
  item->Timestamp = "2 min ago";
  item->Read = false;
}

void __fastcall TMain::InboxMarkRead(TObject *Sender, const String aUserID,
  const String aNotificationID)
{
  // persist it, after checking that aUserID owns aNotificationID
}

// in the message handler that receives the actions the inbox posts
if (oInbox->ProcessAction(vUser, vAction, vNotificationID))
  oHTMX->PushFragment(vGuid, oInbox->GetListFragmentHTML() +
    oInbox->GetBadgeFragmentHTML());
using esegece.sgcWebSockets;

var inbox = new TsgcHTMLComponent_NotificationInbox();
inbox.InboxID = "inbox";
inbox.Title = "Notifications";
inbox.MaxItems = 10;
inbox.OnLoadNotifications += InboxLoad;
inbox.OnMarkRead += InboxMarkRead;
inbox.OnMarkAllRead += InboxMarkAllRead;

// the user comes from the session, never from the form
string user = sgcHTMLSessionHelpers.sgcHTMLRequestSession()?.UserID ?? "";
inbox.LoadNotifications(user);
string html = inbox.HTML;   // bell, unread badge and dropdown

// the application owns the rows: fill the list, newest first
void InboxLoad(object sender, string userID, TsgcHTMLInboxItems list)
{
    var item = list.Add();
    item.Id = "1042";
    item.Title = "New order";
    item.Text = "Order #1042 was placed.";
    item.Timestamp = "2 min ago";
    item.Read = false;
}

void InboxMarkRead(object sender, string userID, string notificationID)
{
    // persist it, after checking that userID owns notificationID
}

// in the message handler that receives the actions the inbox posts
if (inbox.ProcessAction(user, action, notificationId))
    htmx.PushFragment(guid, inbox.GetListFragmentHTML() + inbox.GetBadgeFragmentHTML());

주요 속성 및 메서드

가장 자주 사용하게 되는 멤버.

Items

ItemsTsgcHTMLInboxItems 컬렉션이며, 각 TsgcHTMLInboxItemId, Title, Text, Timestamp, Url, Icon, Read를 갖습니다. 행의 모든 내용은 데이터이며 렌더링될 때 이스케이프되고, Icon도 예외가 아닙니다. 리터럴 글리프를 전달하고, HTML 엔티티나 마크업은 절대 전달하지 마십시오. Url은 정제되며 javascript:data: 링크는 거부됩니다.

저장소 이벤트

컴포넌트는 렌더링 중인 내용만 보관합니다. OnLoadNotifications(aUserID, aList)aList가 이미 비워진 상태로 발생하며, 여기에 해당 사용자의 알림을 최신순으로 채우십시오. OnMarkRead(aUserID, aNotificationID)는 항목이 읽음으로 표시된 뒤에, OnMarkAllRead(aUserID)는 모든 항목이 그렇게 된 뒤에 발생합니다.

서버 측 액션

LoadNotifications(aUserID), MarkRead(aUserID, aNotificationID), MarkAllRead(aUserID)가 실제 작업을 수행합니다. ProcessAction(aUserID, aAction, aNotificationID)는 게시된 액션 하나를 알맞은 메서드로 라우팅하며, 그 액션이 수신함의 액션이 아니면 False를 반환하므로 그 담당자를 계속 찾을 수 있습니다.

게시하는 액션

드롭다운은 inboxMarkRead(필드 action, inbox, id), inboxMarkAllRead, inboxRefresh(필드 action, inbox)를 data-sgc-ws-send 폼으로 게시합니다. inbox 필드는 폼을 렌더링한 수신함의 요소 ID를 담으며, InboxID를 설정했다면 그 값입니다. 수신함이 여럿인 페이지는 이 필드로 액션을 올바른 컴포넌트에 라우팅합니다.

권한 부여

컴포넌트는 UI를 렌더링할 뿐 권한 부여를 강제하지 않습니다. 모든 액션은 클라이언트가 보낸 데이터로 전달되므로, 악의적인 클라이언트는 어떤 액션이나 알림 ID도 위조할 수 있습니다. 마크업에는 사용자 ID가 기록되지 않습니다. 액션을 수행하는 사용자는 폼이 아니라 요청 세션(sgcHTMLRequestSession)에서 가져오고, 무엇이든 유지하기 전에 도착한 알림 ID를 그 사용자가 소유하는지 확인하십시오.

외관

Title은 드롭다운의 제목이고, EmptyText는 표시할 내용이 없을 때의 플레이스홀더이며, BellIcon은 트리거 글리프로, 기본값이 HTML 엔티티인 신뢰된 마크업입니다. MaxItems는 표시되는 행 수를 제한하며(기본값 10, 0이면 모두 표시), ShowMarkAllReadShowBadge는 기본적으로 켜져 있고, AddNotification(aId, aTitle, aText, aTimestamp, aUrl, aIcon)은 행을 추가하거나 같은 ID의 행을 갱신합니다.

실시간 업데이트

모든 알림, 배지, 목록은 고정된 요소 ID를 가집니다. 변경이 하나 있을 때는 페이지를 다시 렌더링하는 대신 GetItemFragmentHTML(aId), GetBadgeFragmentHTML, GetListFragmentHTML로 영향받는 마크업만 렌더링하여 TsgcHTMX_Engine_Server.PushFragment 또는 BroadcastFragment로 푸시하십시오. UnreadCountReadFalse인 항목의 수를 셉니다.

에디션과 채널

이 유닛은 SGC_HTML이 정의된 경우에 컴파일되며, sgcVer.inc는 Android와 iOS에는 이를 정의하지 않습니다. 모든 에디션에서 WebSocket 또는 서버 전송 이벤트를 통해 동작합니다. sgcHTML은 sgcWebSockets와 별도로 판매되는 단독 팩입니다.

페이지 또는 푸시

수신함은 페이지와 푸시 중에서 스스로 선택하지 않습니다. 이는 TsgcHTMLComponent_Notification이 수행하며, NotificationWebPush를 참조하십시오. 각 사용자가 원하는 채널은 NotificationPreferences에서 설정합니다.

계속 살펴보기

온라인 도움말이 찱포넌트의 전체 API 참조 및 사용 가이드입니다.
모든 sgcHTML 컴포넌트80개 이상의 컴포넌트 전체 기능 매트릭스를 둘러보십시오.
무료 체험판 다운로드30일 체험판은 60.HTML 데모 프로젝트를 포함하며, 그중 17.FieldService는 수신함을 사용합니다.
가격전체 소스 코드가 포함된 Single, Team 및 Site 라이선스.
최고의 가성비: All-Access모든 eSeGeCe 제품과 프리미엄 지원이 포함되어 연 €1,059부터 이용할 수 있어요.
All-Access 가격 보기

시작할 준비가 되셨습니까?

무료 체험판을 다운로드하고 Delphi, C++ Builder 및 .NET에서 웹 UI를 구축하기 시작하십시오.