Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

javascript - SignalR与notify.js一起显示实体保存/更新的事件(SignalR with notify.js to display entity saved/updated event)

I have an MVC app that uses SignalR to update a general notification table to relevant people on the home page of the app.

(我有一个使用SignalR来向应用程序主页上的相关人员更新一般通知表的MVC应用程序。)

I have a second page (Supplier page) where I don't want to display the entire table but just notifications specific to information on that page.

(我有第二个页面(“供应商”页面),我不想显示整个表格,而只是显示特定于该页面信息的通知。)

For this page I'm using notify.js ( https://notifyjs.jpillora.com/ ) to display the notification just for that page.

(对于此页面,我使用notify.js https://notifyjs.jpillora.com/显示该页面的通知。)

I've got this to work, but my issue is that for users currently on the page (ie the ones that actually update supplier information) don't see this notification but others users do.

(我已经做到了这一点,但是我的问题是,对于当前在页面上的用户(即实际上在更新供应商信息的用户)而言,看不到此通知,而其他用户却可以看到。)

The user enters information about the supplier in a modal popup.

(用户在模式弹出窗口中输入有关供应商的信息。)

The notification box tries to appear when the user clicks "Save" but disappears as soon as the POST method finishes.

(当用户单击“保存”时,通知框尝试显示,但是在POST方法完成后消失。)

I have set the 'autoHide' option with notify.js to false and 'clickToHide' to true so the user has to click to dismiss the notifications.

(我已将notify.js的'autoHide'选项设置为false,将'clickToHide'选项设置为true,因此用户必须单击以关闭通知。)

My question would be is there a way to temporarily "pause" the SignalR event so that the POST finishes and then the notification is displayed?

(我的问题是,是否有一种方法可以暂时“暂停” SignalR事件,以便POST完成,然后显示通知?)

This is my SignalR Javascript event to display the notification on the supplier "Index" page

(这是我的SignalR Javascript事件,用于在供应商的“索引”页面上显示通知)

var hub = $.connection.notificationsUpdatedHub;
hub.client.displaySupplierNotification = function (description) {
    //console.log(description);
    $.notify(description, {
        autoHide: false,
        clickToHide: true,
        style: 'notify-collins'
    });
}
$.connection.hub.start();

With the following event handler (to filter for supplier specific notifications)

(使用以下事件处理程序(以过滤特定于供应商的通知))

public void Handle(NotificationsUpdatedEvent notificationEvent)
{
    var nDTO = notificationEvent.NotificationDTO;
    var context = GlobalHost.ConnectionManager.GetHubContext<NotificationsUpdatedHub>();

    context.Clients.All.appendToNotificationsTable(nDTO.DateRaised.ToString(), 
                                                   nDTO.Description, 
                                                   ConvertStateToIcon(nDTO.NotificationState));

    if (nDTO.Code == NotificationCodes.UnableToUpdateSupplier ||
        nDTO.Code == NotificationCodes.UpdatedSupplierInformation)
    {
        context.Clients.All.displaySupplierNotification(nDTO.Description);
    }
}

And the POST method in the managing suppliers controller

(以及供应商管理者控制器中的POST方法)

[HttpPost]
public ActionResult SaveSupplier(int id, string name, string telephone)
{
    SupplierDTO supplierDTO = new SupplierDTO(id, name, telephone);
    try
    {
        ValidateModel(supplierDTO);
        _managingSuppliersService.UpdateSupplier(supplierDTO);
        return RedirectToAction("Index");
    }
    catch (Exception)
    {
        return PartialView("_EditSupplier", supplierDTO);
    }
}
  ask by NightComets translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...